Example usage for org.jfree.data.general DatasetUtilities createCategoryDataset

List of usage examples for org.jfree.data.general DatasetUtilities createCategoryDataset

Introduction

In this page you can find the example usage for org.jfree.data.general DatasetUtilities createCategoryDataset.

Prototype

public static CategoryDataset createCategoryDataset(Comparable[] rowKeys, Comparable[] columnKeys,
        double[][] data) 

Source Link

Document

Creates a CategoryDataset that contains a copy of the data in an array (instances of Double are created to represent the data items).

Usage

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

/**
 * Starting point for the demo./*from w  ww.j  av a2s .c o  m*/
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create a chart
    final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 },
            { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 },
            { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } };
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    JFreeChart chart = null;
    final boolean drilldown = true;

    if (drilldown) {
        final CategoryAxis3D categoryAxis = new CategoryAxis3D("Category");
        final ValueAxis valueAxis = new NumberAxis3D("Value");
        final BarRenderer3D renderer = new BarRenderer3D();
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp"));
        final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        chart = ChartFactory.createBarChart3D("Bar Chart", // chart title
                "Category", // domain axis label
                "Value", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, false);
    }
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("barchart101.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("barchart101.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"barchart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }

}

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

/**
 * Starting point for the demo.//from   w w w .j  av a 2 s  . c  o m
 *
 * @param args  ignored.
 */
public static void main(final String[] args) {

    // create a chart
    final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 },
            { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 },
            { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } };
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    JFreeChart chart = null;
    final boolean drilldown = true;

    if (drilldown) {
        final CategoryAxis categoryAxis = new CategoryAxis("Category");
        final ValueAxis valueAxis = new NumberAxis("Value");
        final BarRenderer renderer = new BarRenderer();
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        renderer.setItemURLGenerator(new StandardCategoryURLGenerator("bar_chart_detail.jsp"));
        final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        chart = new JFreeChart("Bar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        chart = ChartFactory.createBarChart("Vertical Bar Chart", // chart title
                "Category", // domain axis label
                "Value", // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, true, // include legend
                true, false);
    }
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("barchart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("barchart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"barchart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }

}

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

private static CategoryDataset createDataset() {
    double ad[][] = { { 1.0D, 4D, 3D, 5D, 5D, 7D, 7D, 8D }, { 5D, 7D, 6D, 8D, 4D, 4D, 2D, 1.0D },
            { 4D, 3D, 2D, 3D, 6D, 3D, 4D, 3D } };
    CategoryDataset categorydataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", ad);
    return categorydataset;
}

From source file:com.kiyoshi.gui.AreaChart.java

public JPanel getChart() {
    // create a dataset...
    final double[][] data = new double[][] { { 1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
            { 5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 }, { 4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 } };

    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    // create the chart...
    final JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart);
    JPanel b = new JPanel();
    JPanel c = (JPanel) b.add(chartPanel);
    return c;// ww w . ja va  2 s  .  c  o  m
}

From source file:com.mergano.core.AreaChart.java

public ChartPanel getChart() {
    // create a dataset...
    final double[][] data = new double[][] {
            { 34.0, 10.0, 2.0, 25.0, 53.0, 79.0, 27.0, 13.0, 34.0, 13.0, 5.0, 39.0, 69.0, 85.0, 55.0, 32.0,
                    48.0, 25.0, 53.0, 79.0, 27.0, 13.0, 34.0, 13.0, 0, 79.0, 27.0, 13.0, 34.0, 13.0, } };

    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("May ", "Day ", data);
    // create the chart...
    final JFreeChart chart = createChart(dataset);
    chartPanel = new ChartPanel(chart);

    return chartPanel;
}

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

/**
 * Creates a new demo instance.//from   www .  ja v a 2  s. c  om
 *
 * @param title  the frame title.
 */
public LayeredBarChartDemo2(final String title) {

    super(title);

    // create a dataset...
    final double[][] data = new double[][] { { 41.0, 33.0, 22.0, 64.0, 42.0, 62.0, 22.0, 14.0 },
            { 55.0, 63.0, 55.0, 48.0, 54.0, 37.0, 41.0, 39.0 },
            { 57.0, 75.0, 43.0, 33.0, 63.0, 46.0, 57.0, 33.0 } };

    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Factor ", data);

    // create the chart...
    final CategoryAxis categoryAxis = new CategoryAxis("Category");
    final ValueAxis valueAxis = new NumberAxis("Score (%)");

    final CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, new LayeredBarRenderer());

    plot.setOrientation(PlotOrientation.VERTICAL);
    final JFreeChart chart = new JFreeChart("Layered Bar Chart Demo 2", JFreeChart.DEFAULT_TITLE_FONT, plot,
            true);

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

    final LayeredBarRenderer renderer = (LayeredBarRenderer) plot.getRenderer();

    // we can set each series bar width individually or let the renderer manage a standard view.
    // the width is set in percentage, where 1.0 is the maximum (100%).
    renderer.setSeriesBarWidth(0, 1.0);
    renderer.setSeriesBarWidth(1, 0.7);
    renderer.setSeriesBarWidth(2, 0.5);

    renderer.setItemMargin(0.01);

    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryMargin(0.25);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setLowerMargin(0.05);

    // 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:org.jfree.chart.demo.CategoryStepChartDemo.java

/**
 * Creates a new demo application./*from w ww. j av  a2  s  . c o m*/
 *
 * @param title  the frame title.
 */
public CategoryStepChartDemo(final String title) {

    super(title);

    // create a dataset...
    final double[][] data = new double[][] { { 1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
            { 5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 }, { 4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 } };

    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    // create the chart...
    final JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(500, 270));
    chartPanel.setEnforceFileExtensions(false);

    setContentPane(chartPanel);

}

From source file:j2se.jfreechart.barchart.BarChartDemo2.java

/**
 * Creates a sample dataset./* ww  w  .  j a v  a 2  s. c o m*/
 * 
 * @return A dataset.
 */
private CategoryDataset createDataset() {
    final double[][] data = new double[][] { { 1.0, 43.0, 35.0, 58.0, 54.0, 77.0, 71.0, 89.0 },
            { 54.0, 75.0, 63.0, 83.0, 43.0, 46.0, 27.0, 13.0 },
            { 41.0, 33.0, 22.0, 34.0, 62.0, 32.0, 42.0, 34.0 } };
    return DatasetUtilities.createCategoryDataset("Series ", "Factor ", data);
}

From source file:com.twocents.test.ui.chart.MultipieChart.java

/**
 * Creates a sample dataset.//from w  ww .ja  v  a  2 s  .  com
 * 
 * @return A sample dataset.
 */
private CategoryDataset createDataset() {
    final double[][] data = new double[][] { { 3.0, 4.0, 3.0, 5.0 }, { 5.0, 7.0, 6.0, 8.0 },
            { 5.0, 7.0, 3.0, 8.0 }, { 1.0, 2.0, 3.0, 4.0 }, { 2.0, 3.0, 2.0, 3.0 } };
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Region ", "Sales/Q", data);
    return dataset;
}

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

/**
 * Saves the chart image and HTML.//from  w w w .jav a2  s . c  o  m
 */
public void saveImageAndHTML() {

    // create a dataset
    final double[][] data = new double[][] { { 56.0, -12.0, 34.0, 76.0, 56.0, 100.0, 67.0, 45.0 },
            { 37.0, 45.0, 67.0, 25.0, 34.0, 34.0, 100.0, 53.0 },
            { 43.0, 54.0, 34.0, 34.0, 87.0, 64.0, 73.0, 12.0 } };
    final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Type ", data);

    final JFreeChart chart = createChart(dataset);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("areachart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("areachart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"areachart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
}