Example usage for org.jfree.data.category DefaultCategoryDataset addValue

List of usage examples for org.jfree.data.category DefaultCategoryDataset addValue

Introduction

In this page you can find the example usage for org.jfree.data.category DefaultCategoryDataset addValue.

Prototype

public void addValue(double value, Comparable rowKey, Comparable columnKey) 

Source Link

Document

Adds a value to the table.

Usage

From source file:org.fhaes.fhrecorder.view.GraphSummaryOverlay.java

/**
 * This method will create the data set corresponding to the events bar chart (histogram) which JFreeChart uses to create the graph.
 * //from w ww . j  a v a 2 s.  co  m
 * @param inData This is the list of the incoming YearSummary objects. It is the data used to create the Events histogram.
 * @return This method returns the CategoryDataset object that JFreeChart needs to create the Event bar graph.
 */
private static CategoryDataset createEventsDataset(List<YearSummary> inData) {

    DefaultCategoryDataset eventsData = new DefaultCategoryDataset();

    for (YearSummary dataItem : inData)
        eventsData.addValue(dataItem.getNumEvents(), "# Of Events", Integer.toString(dataItem.getYear()));

    return new SlidingCategoryDataset(eventsData, 0, FileController.MAX_VISIBLE_GRAPH_COLUMNS);
}

From source file:org.fhaes.fhrecorder.view.GraphSummaryOverlay.java

/**
 * This method will create the data set corresponding to the samples line graph which JFreeChart uses to create the graph.
 * //from  w  w  w. ja  v  a  2 s .co  m
 * @param inData This is the list of the incoming YearSummary objects. It is the data used to create the number of samples line.
 * @return This method returns the CategoryDataset object that JFreeChart needs to create the samples graph.
 */
private static CategoryDataset createSamplesDataset(List<YearSummary> inData) {

    DefaultCategoryDataset samplesData = new DefaultCategoryDataset();

    for (YearSummary dataItem : inData)
        samplesData.addValue(dataItem.getNumSamples(), "# Of Samples", Integer.toString(dataItem.getYear()));

    return new SlidingCategoryDataset(samplesData, 0, FileController.MAX_VISIBLE_GRAPH_COLUMNS);
}

From source file:es.bsc.autonomic.powermodeller.graphics.TotalPowerVsPredictionDecomposed.java

private static void addColumnToDefaultCategoryDataSet(DefaultCategoryDataset ds, String name,
        List<Double> col) {
    for (int i = 0; i < col.size(); i++) {
        ds.addValue(col.get(i), name, Integer.toString(i));
    }//from  www  .j  a  va  2s. c  o  m
}

From source file:org.fhaes.fhrecorder.view.GraphSummaryOverlay.java

/**
 * This method will create the data set corresponding to the recorders line graph which JFreeChart uses to create the graph.
 * //from  w ww. j a  v a 2 s  .  co  m
 * @param inData This is the list of the incoming YearSummary objects. It is the data used to create the number of recorders line.
 * @return This method returns the CategoryDataset object that JFreeChart needs to create the recorders graph.
 */
private static CategoryDataset createRecordersDataset(List<YearSummary> inData) {

    /**
     * WARNING - the value of recording years does not match that of FHFileReader. There are special cases not currently handled by
     * FHRecorder
     */
    DefaultCategoryDataset recordersData = new DefaultCategoryDataset();

    for (YearSummary dataItem : inData)
        recordersData.addValue(dataItem.getNumRecorders(), "# Of Recorders",
                Integer.toString(dataItem.getYear()));

    return new SlidingCategoryDataset(recordersData, 0, FileController.MAX_VISIBLE_GRAPH_COLUMNS);
}

From source file:gui.MainForm.java

private static CategoryDataset createDataset() {
    String s = "?";
    String s1 = "??";
    String s2 = "??";
    String s3 = "1";
    String s4 = "2";
    String s5 = "3";
    String s6 = "4";
    String s7 = "5";
    DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
    defaultcategorydataset.addValue(1.0D, s, s3);
    defaultcategorydataset.addValue(4D, s, s4);
    defaultcategorydataset.addValue(3D, s, s5);
    defaultcategorydataset.addValue(5D, s, s6);
    defaultcategorydataset.addValue(5D, s, s7);
    defaultcategorydataset.addValue(5D, s1, s3);
    defaultcategorydataset.addValue(7D, s1, s4);
    defaultcategorydataset.addValue(6D, s1, s5);
    defaultcategorydataset.addValue(8D, s1, s6);
    defaultcategorydataset.addValue(4D, s1, s7);
    defaultcategorydataset.addValue(4D, s2, s3);
    defaultcategorydataset.addValue(3D, s2, s4);
    defaultcategorydataset.addValue(2D, s2, s5);
    defaultcategorydataset.addValue(3D, s2, s6);
    defaultcategorydataset.addValue(6D, s2, s7);
    return defaultcategorydataset;
}

From source file:jgnash.ui.budget.BudgetSparkline.java

public static Icon getSparklineImage(final List<BigDecimal> amounts) {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final boolean[] negate = new boolean[amounts.size()];

    for (int i = 0; i < amounts.size(); i++) {
        dataset.addValue(amounts.get(i), CATEGORY, i);
        negate[i] = amounts.get(i).signum() == -1;
    }//from  w w  w.j av a  2 s .  c  o  m

    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setTickLabelsVisible(false);
    xAxis.setTickMarksVisible(false);
    xAxis.setAxisLineVisible(false);
    xAxis.setVisible(false);

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setAutoRangeIncludesZero(true);
    yAxis.setAutoRange(true);
    yAxis.setVisible(false);

    BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(final int row, final int column) {
            return negate[column] ? Color.RED : Color.BLACK;
        }
    };

    renderer.setShadowVisible(false);
    renderer.setBarPainter(new StandardBarPainter());

    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    plot.setInsets(INSETS);
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(CLEAR);

    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(CLEAR);

    Icon icon = EMPTY_ICON;

    try {
        byte[] image = ENCODER
                .encode(chart.createBufferedImage(DEFAULT_WIDTH, DEFAULT_HEIGHT, BufferedImage.BITMASK, null));
        icon = new ImageIcon(image);
    } catch (IOException ex) {
        Logger.getLogger(BudgetSparkline.class.getName()).log(Level.SEVERE, null, ex);
    }

    return icon;
}

From source file:net.sf.jasperreports.components.spiderchart.SpiderChartRendererEvaluator.java

public static DefaultCategoryDataset getSampleDataset() {
    if (sampleDataset == null) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "Series 1", "Category 1");
        dataset.addValue(5.0, "Series 1", "Category 2");
        dataset.addValue(4.0, "Series 1", "Category 3");
        dataset.addValue(3.0, "Series 1", "Category 4");
        dataset.addValue(6.0, "Series 1", "Category 5");
        dataset.addValue(4.0, "Series 1", "Category 6");
        dataset.addValue(3.0, "Series 1", "Category 7");
        dataset.addValue(5.0, "Series 2", "Category 1");
        dataset.addValue(7.0, "Series 2", "Category 2");
        dataset.addValue(8.0, "Series 2", "Category 3");
        dataset.addValue(6.0, "Series 2", "Category 4");
        dataset.addValue(9.0, "Series 2", "Category 5");
        dataset.addValue(8.0, "Series 2", "Category 6");
        dataset.addValue(7.0, "Series 2", "Category 7");
        dataset.addValue(5.0, "Series 3", "Category 1");
        dataset.addValue(4.0, "Series 3", "Category 2");
        dataset.addValue(6.0, "Series 3", "Category 3");
        dataset.addValue(3.0, "Series 3", "Category 4");
        dataset.addValue(2.0, "Series 3", "Category 5");
        dataset.addValue(7.0, "Series 3", "Category 6");
        dataset.addValue(5.0, "Series 3", "Category 7");

        sampleDataset = dataset;//w ww  . j av  a  2  s  .  co m
    }

    return sampleDataset;
}

From source file:userinterface.CyberSecurity.ChartFactory.java

public static ChartPanel createChart(UserAccount account) {
    Map<String, LoginDetails> loginDetails = account.getLoginDetails();
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();

    Collection<LoginDetails> values = loginDetails.values();

    for (LoginDetails details : values) {
        dataset1.addValue(TimeUnit.MILLISECONDS.toHours(details.getLogoutTime() - details.getLoginTime()),
                HOURS_WORKED_BY_USER, details.getLoginDate());
        dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, details.getLoginDate());
    }// ww  w  .jav a  2  s  .  c  om

    dataset1.addValue(2, HOURS_WORKED_BY_USER, "4-19-2016");
    dataset1.addValue(3, HOURS_WORKED_BY_USER, "4-20-2016");
    dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-19-2016");
    dataset2.addValue(2.5, MINIMUM_WORKING_HOURS, "4-20-2016");

    final CategoryItemRenderer renderer = new BarRenderer();

    final CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset1);
    plot.setRenderer(renderer);

    plot.setDomainAxis(new CategoryAxis("Date"));
    plot.setRangeAxis(new NumberAxis("Hours"));

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    // now create the second dataset and renderer...
    final CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    final JFreeChart chart = new JFreeChart(plot);
    chart.setTitle("Employee work hours");

    chart.setBackgroundPaint(Color.WHITE);
    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    return chartPanel;
}

From source file:org.sonar.plugins.core.charts.DistributionBarChart.java

static void configureValues(DefaultCategoryDataset dataset, String[] series, String xSuffix) {
    int index = 0;
    while (index < series.length) {
        String[] pairs = StringUtils.split(series[index], ";");
        if (pairs.length == 0) {
            dataset.addValue((Number) 0.0, index, "0");

        } else {/* w  w w  .j av a  2  s  .c o m*/
            for (String pair : pairs) {
                String[] keyValue = StringUtils.split(pair, "=");
                double val = Double.parseDouble(keyValue[1]);
                dataset.addValue((Number) val, index, keyValue[0] + xSuffix);
            }
        }
        index++;
    }

}

From source file:cl.apr.pdf.chart.BarChartAviso.java

public static BufferedImage crearBarchart(List<BarChartItem> barChartItems) {
    BufferedImage bi = null;/*from  w  ww.j  a  v a 2s .  c o  m*/
    try {

        ChartFactory.setChartTheme(StandardChartTheme.createJFreeTheme());
        //ChartFactory.setChartTheme(StandardChartTheme.createDarknessTheme());

        /* Step - 1: Define the data for the bar chart  */
        DefaultCategoryDataset my_bar_chart_dataset = new DefaultCategoryDataset();
        int i = 0;
        for (BarChartItem barChartItem : barChartItems) {
            if (barChartItem.getNombre().equals("-")) {
                my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", (++i) + "");
            } else
                my_bar_chart_dataset.addValue(barChartItem.getValor(), "serie", barChartItem.getNombre());
        }
        //                my_bar_chart_dataset.addValue(34, "mes", "Ene");
        //                my_bar_chart_dataset.addValue(25, "mes", "Feb");
        //                my_bar_chart_dataset.addValue(22, "mes", "Mar");
        //                my_bar_chart_dataset.addValue(12, "mes", "Abr");
        //                my_bar_chart_dataset.addValue(40, "mes", "May");
        //                my_bar_chart_dataset.addValue(30, "mes", "jun");
        //                my_bar_chart_dataset.addValue(2, "mes", "Jul");
        //                my_bar_chart_dataset.addValue(15, "mes", "Ago");

        /* Step -2:Define the JFreeChart object to create bar chart */
        //JFreeChart chart=ChartFactory.createBarChart("Detalle de sus consumos","","MT3",my_bar_chart_dataset,PlotOrientation.VERTICAL,true,true,false);    
        JFreeChart chart = ChartFactory.createBarChart("", "", "MT3", my_bar_chart_dataset,
                PlotOrientation.VERTICAL, true, true, false);

        //chart.setBackgroundPaint(Color.lightGray);
        // get a reference to the plot for further customisation... 
        final CategoryPlot plot = chart.getCategoryPlot();
        CategoryItemRenderer renderer = new CustomRenderer();

        renderer.setSeriesPaint(0, Color.DARK_GRAY);

        plot.setRenderer(renderer);
        plot.setBackgroundPaint(Color.white);

        chart.setBorderVisible(false);
        chart.setBackgroundPaint(Color.white);
        chart.setBorderStroke(null);
        chart.getLegend().visible = false;
        /* Step -3: Write the output as PNG file with bar chart information */
        int width = 480; /* Width of the image */
        int height = 250; /* Height of the image */
        bi = chart.createBufferedImage(width, height);

        /*
                
        File BarChart=new File("output_chart.png");              
        ChartUtilities.saveChartAsPNG(BarChart,BarChartObject,width,height); 
                */
    } catch (Exception i) {
        System.out.println(i);
    }

    return bi;
}