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

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

Introduction

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

Prototype

public DefaultCategoryDataset() 

Source Link

Document

Creates a new (empty) dataset.

Usage

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.WinLose.java

@Override
public DatasetMap calculateValue() throws Exception {
    logger.debug("IN");

    DatasetMap datasets = super.calculateValue();
    if (datasets == null || yearsDefined == null) {
        logger.error("Error in TrargetCharts calculate value");
        return null;
    }//w w w  . j  a v  a2s.  c  om
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    datasets.addDataset("1", dataset);

    if (datasets != null && yearsDefined.isEmpty()) {
        logger.warn("no rows found with dataset");
    } else {

        // Check if defining target and baseline
        Double mainTarget = null;
        Double mainBaseline = null;
        if (mainThreshold == null) {
            logger.error("No main target or baseline defined, not possible to draw the chart");
        } else {
            if (useTargets)
                mainTarget = mainThreshold;
            else
                mainBaseline = mainThreshold;
            nullValues = new Vector<String>();

            // run all the years defined
            for (Iterator iterator = yearsDefined.iterator(); iterator.hasNext();) {
                String currentYearS = (String) iterator.next();
                int currentYear = Integer.valueOf(currentYearS).intValue();
                boolean stop = false;
                for (int i = 1; i < 13 && stop == false; i++) {
                    Month currentMonth = new Month(i, currentYear);
                    // if it is the first year and th ecurrent month is previous than the first month
                    if (currentYearS.equalsIgnoreCase(yearsDefined.first()) && i < firstMonth.getMonth()) {
                        // continue
                    } else {
                        TimeSeriesDataItem item = timeSeries.getDataItem(currentMonth);
                        if (item != null && item.getValue() != null) {
                            double v = item.getValue().doubleValue();
                            double result = 0;
                            if (mainTarget != null) {
                                result = (v >= mainTarget.doubleValue()) ? WIN : LOSE;
                            } else if (mainBaseline != null) {
                                result = (v > mainBaseline.doubleValue()) ? LOSE : WIN;
                            } else {
                                logger.warn("could not find a threshold");
                            }

                            dataset.addValue(result, timeSeries.getKey(), "" + i + "-" + currentYear);

                        } else {
                            if (wlt_mode.doubleValue() == 5) {
                                dataset.addValue(0.001, timeSeries.getKey(), "" + i + "-" + currentYear);
                                nullValues.add("" + i + "-" + currentYear);
                            } else {
                                dataset.addValue(0.0, timeSeries.getKey(), "" + i + "-" + currentYear);
                            }
                        }
                        // if it is last year and current month is after the last month stop 
                        if (currentYearS.equalsIgnoreCase(lastYear) && i >= lastMonth.getMonth()) {
                            stop = true;
                        }

                    }
                }

            }
        }
    }
    logger.debug("OUT");
    return datasets;
}

From source file:it.eng.spagobi.engines.kpi.bo.charttypes.trendcharts.LineChart.java

public DatasetMap calculateValue(String result) throws Exception {

    logger.debug("IN");
    res = result;/*from  www . j a v  a2  s.c om*/
    categories = new HashMap();
    datasetMap = new DatasetMap();

    SourceBean sbRows = SourceBean.fromXMLString(res);
    List listAtts = sbRows.getAttributeAsList("ROW");

    // run all categories (one for each row)
    categoriesNumber = 0;

    datasetMap.getDatasets().put("line", new DefaultCategoryDataset());

    boolean first = true;

    for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) {
        SourceBean category = (SourceBean) iterator.next();
        List atts = category.getContainedAttributes();

        HashMap series = new LinkedHashMap();
        HashMap additionalValues = new LinkedHashMap();
        String catValue = "";

        String nameP = "";
        String value = "";

        //run all the attributes, to define series!
        int numColumn = 0;
        if (!atts.isEmpty()) {
            for (Iterator iterator2 = atts.iterator(); iterator2.hasNext();) {
                numColumn++;
                SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next();

                nameP = new String(object.getKey());
                value = new String((String) object.getValue());
                logger.debug("Name:" + nameP);
                logger.debug("Value:" + value);
                if (nameP.equalsIgnoreCase("x")) {
                    catValue = value;
                    catValue = catValue.substring(0, 16);
                    categoriesNumber = categoriesNumber + 1;
                    categories.put(new Integer(categoriesNumber), value);

                } else {
                    series.put(nameP, value);
                }
            }
        }

        String nameS = "KPI_VALUE";
        IMessageBuilder msgBuilder = MessageBuilderFactory.getMessageBuilder();
        String labelS = msgBuilder.getMessage("sbi.kpi.labels");
        String valueS = (String) series.get(nameS);
        if (valueS != null) {
            ((DefaultCategoryDataset) (datasetMap.getDatasets().get("line")))
                    .addValue(Double.valueOf(valueS).doubleValue(), labelS, catValue);
        }
    }
    logger.debug("OUT");
    return datasetMap;
}

From source file:playground.artemc.calibration.charts.AddSecondChart.java

public AddSecondChart(final JFreeChart jFreeChart, final String yAxisLabel, final String[] categories,
        final Integer lowerLimit, final Integer upperLimit) {

    this.chart = jFreeChart;
    this.plot = chart.getCategoryPlot();
    this.categories = categories;
    this.dataset = new DefaultCategoryDataset();
    this.yAxisLabel = yAxisLabel;
    this.upperLimit = upperLimit;
    this.lowerLimit = lowerLimit;

}

From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo1a.java

/**
 * Creates a sample dataset.//  w w  w  .jav  a 2 s.c o m
 * 
 * @return The dataset.
 */
protected CategoryDataset createDataset(boolean isDemo) {
    if (isDemo) {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(212, "Classes", "JDK 1.0");
        dataset.addValue(504, "Classes", "JDK 1.1");
        dataset.addValue(1520, "Classes", "SDK 1.2");
        dataset.addValue(1842, "Classes", "SDK 1.3");
        dataset.addValue(2991, "Classes", "SDK 1.4");
        return dataset;
    } else
        return super.createDataset(false);
}

From source file:org.jfree.data.category.DefaultCategoryDatasetTest.java

/**
 * Some checks for the getValue() method.
 *//*from   w w  w  .ja va2  s.  c om*/
@Test
public void testGetValue() {
    DefaultCategoryDataset d = new DefaultCategoryDataset();
    d.addValue(1.0, "R1", "C1");
    assertEquals(new Double(1.0), d.getValue("R1", "C1"));
    boolean pass = false;
    try {
        d.getValue("XX", "C1");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);

    pass = false;
    try {
        d.getValue("R1", "XX");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:Visuals.BarChart.java

public ChartPanel drawBarChart() {
    DefaultCategoryDataset bardataset = new DefaultCategoryDataset();
    bardataset.addValue(new Double(low), "Low (" + low + ")", lowValue);
    bardataset.addValue(new Double(medium), "Medium (" + medium + ")", mediumValue);
    bardataset.addValue(new Double(high), "High (" + high + ")", highValue);
    bardataset.addValue(new Double(critical), "Critical (" + critical + ")", criticalValue);

    JFreeChart barchart = ChartFactory.createBarChart(title, // Title  
            riskCategory, riskCountTitle, bardataset // Dataset   
    );/*  ww w. j  ava  2  s . c om*/

    final CategoryPlot plot = barchart.getCategoryPlot();
    CategoryItemRenderer renderer = new CustomRenderer();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    renderer.setBaseItemLabelGenerator(
            new StandardCategoryItemLabelGenerator(riskCountTitle, NumberFormat.getInstance()));

    DecimalFormat df = new DecimalFormat("##");
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator("{2}", df));
    Font m1Font;
    m1Font = new Font("Cambria", Font.BOLD, 16);
    renderer.setItemLabelFont(m1Font);
    renderer.setItemLabelPaint(null);

    //barchart.removeLegend();
    plot.setRenderer(renderer);
    //renderer.setPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE5, TextAnchor.CENTER));
    //renderer.setItemLabelsVisible(true);
    barchart.getCategoryPlot().setRenderer(renderer);

    LegendItemCollection chartLegend = new LegendItemCollection();
    Shape shape = new Rectangle(10, 10);
    chartLegend.add(new LegendItem("Low (" + low + ")", null, null, null, shape, new Color(230, 219, 27)));
    chartLegend
            .add(new LegendItem("Medium (" + medium + ")", null, null, null, shape, new Color(85, 144, 176)));
    chartLegend.add(new LegendItem("High (" + high + ")", null, null, null, shape, new Color(230, 90, 27)));
    chartLegend.add(
            new LegendItem("Critical (" + critical + ")", null, null, null, shape, new Color(230, 27, 27)));
    plot.setFixedLegendItems(chartLegend);
    plot.setBackgroundPaint(new Color(210, 234, 243));
    ChartPanel chartPanel = new ChartPanel(barchart);
    return chartPanel;
}

From source file:edu.cuny.cat.ui.TraderDistributionPanel.java

public TraderDistributionPanel() {

    registry = GameController.getInstance().getRegistry();
    clock = GameController.getInstance().getClock();

    dataset = new DefaultCategoryDataset();

    setTitledBorder("Trader Distribution");

    chart = ChartFactory.createLineChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false);
    chart.setBackgroundPaint(getBackground());
    final CategoryPlot categoryplot = chart.getCategoryPlot();
    categoryplot.setOrientation(PlotOrientation.HORIZONTAL);
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    final LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    UIUtils.setDefaultLineAndShapeRendererStyle(lineandshaperenderer);
    lineandshaperenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    final NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setUpperMargin(0.12D);/*from   www.ja v  a2 s  .  co m*/

    final ChartPanel chartPanel = new ChartPanel(chart);
    add(chartPanel, BorderLayout.CENTER);
}

From source file:org.matsim.counts.algorithms.graphs.BiasErrorGraph.java

@Override
public JFreeChart createChart(final int nbr) {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();

    this.errorStats = new ComparisonErrorStatsCalculator(this.ccl_);

    double[] meanRelError = errorStats.getMeanRelError();
    //      double[] meanAbsError = errorStats.getMeanAbsError();
    double[] meanAbsBias = errorStats.getMeanAbsBias();

    for (int h = 0; h < 24; h++) {
        dataset0.addValue(meanRelError[h], "Mean rel error", Integer.toString(h + 1));
        //         dataset1.addValue(meanAbsError[h], "Mean abs error", Integer.toString(h + 1));
        dataset1.addValue(meanAbsBias[h], "Mean abs bias", Integer.toString(h + 1));
    }/*  w w w  .j a  va2  s.  c om*/

    this.chart_ = ChartFactory.createLineChart("", "Hour", "Mean rel error [%]", dataset0,
            PlotOrientation.VERTICAL, true, // legend?
            true, // tooltips?
            false // URLs?
    );
    CategoryPlot plot = this.chart_.getCategoryPlot();
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    plot.setDataset(1, dataset1);
    plot.mapDatasetToRangeAxis(1, 1);

    final LineAndShapeRenderer renderer = new LineAndShapeRenderer();
    renderer.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    plot.setRenderer(0, renderer);

    final CategoryAxis axis1 = new CategoryAxis("Hour");
    axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7));
    plot.setDomainAxis(axis1);

    //      final ValueAxis axis2 = new NumberAxis("Mean abs {bias, error} [veh/h]");
    final ValueAxis axis2 = new NumberAxis("Mean abs bias [veh/h]");
    plot.setRangeAxis(1, axis2);

    final ValueAxis axis3 = plot.getRangeAxis(0);
    axis3.setRange(0.0, 100.0);

    final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    renderer2.setSeriesToolTipGenerator(0, new StandardCategoryToolTipGenerator());
    renderer2.setSeriesToolTipGenerator(1, new StandardCategoryToolTipGenerator());
    //      renderer2.setSeriesPaint(0, Color.black);
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);

    return this.chart_;
}

From source file:org.jfree.chart.demo.MinMaxCategoryPlotDemo.java

/**
 * Creates a new demo./*www .j  a  v a2s.  c  o m*/
 *
 * @param title  the frame title.
 */
public MinMaxCategoryPlotDemo(final String title) {

    super(title);

    // create a dataset...
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(1.0, "First", "Category 1");
    dataset.addValue(4.0, "First", "Category 2");
    dataset.addValue(3.0, "First", "Category 3");
    dataset.addValue(5.0, "First", "Category 4");
    dataset.addValue(5.0, "First", "Category 5");
    dataset.addValue(7.0, "First", "Category 6");
    dataset.addValue(7.0, "First", "Category 7");
    dataset.addValue(8.0, "First", "Category 8");
    dataset.addValue(5.0, "Second", "Category 1");
    dataset.addValue(7.0, "Second", "Category 2");
    dataset.addValue(6.0, "Second", "Category 3");
    dataset.addValue(8.0, "Second", "Category 4");
    dataset.addValue(4.0, "Second", "Category 5");
    dataset.addValue(4.0, "Second", "Category 6");
    dataset.addValue(2.0, "Second", "Category 7");
    dataset.addValue(1.0, "Second", "Category 8");
    dataset.addValue(4.0, "Third", "Category 1");
    dataset.addValue(3.0, "Third", "Category 2");
    dataset.addValue(2.0, "Third", "Category 3");
    dataset.addValue(3.0, "Third", "Category 4");
    dataset.addValue(6.0, "Third", "Category 5");
    dataset.addValue(3.0, "Third", "Category 6");
    dataset.addValue(4.0, "Third", "Category 7");
    dataset.addValue(3.0, "Third", "Category 8");

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Min/Max Category Plot", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.yellow);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setRenderer(new MinMaxCategoryRenderer());
    // OPTIONAL CUSTOMISATION COMPLETED.

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:net.nosleep.superanalyzer.analysis.views.MostPlayedAAView.java

private void createPanel() {
    _artistDataset = new DefaultCategoryDataset();
    _albumDataset = new DefaultCategoryDataset();

    _artistChart = createChart(Misc.getString("MOST_PLAYED_ARTISTS"), "", _artistDataset);
    _albumChart = createChart(Misc.getString("MOST_PLAYED_ALBUMS"), "", _albumDataset);

    refreshDataset();//from w  w  w.j a  va 2 s. c  om

    _artistChartPanel = new ChartPanel(_artistChart);
    _albumChartPanel = new ChartPanel(_albumChart);
}