Example usage for org.jfree.chart.axis CategoryAxis CategoryAxis

List of usage examples for org.jfree.chart.axis CategoryAxis CategoryAxis

Introduction

In this page you can find the example usage for org.jfree.chart.axis CategoryAxis CategoryAxis.

Prototype

public CategoryAxis(String label) 

Source Link

Document

Constructs a category axis, using default values where necessary.

Usage

From source file:playground.wrashid.tryouts.mess.Boxplot.java

/**
 * @param args/* w w w .  java  2  s. co m*/
 */
public static void main(String[] args) {

    final BoxAndWhiskerCategoryDataset dataset = createSampleDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart("Box-and-Whisker Demo", "x", "y", dataset,
            true);
    final ChartPanel chartPanel = new ChartPanel(chart);

    int width = 500;
    int height = 300;

    try {
        ChartUtilities.saveChartAsPNG(new File("boxPlot.png"), chart, width, height);
    } catch (IOException e) {

    }

}

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

/**
 * Starting point for the demo./*from  w  ww  . j a  v  a  2  s. co 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 JFreeChart createChart(CategoryDataset categorydataset) {
    CategoryStepRenderer categorysteprenderer = new CategoryStepRenderer(true);
    categorysteprenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
    CategoryAxis categoryaxis = new CategoryAxis("Category");
    NumberAxis numberaxis = new NumberAxis("Value");
    CategoryPlot categoryplot = new CategoryPlot(categorydataset, categoryaxis, numberaxis,
            categorysteprenderer);// w  w  w  . j a v a 2s  .  com
    JFreeChart jfreechart = new JFreeChart("Category Step Chart", categoryplot);
    jfreechart.setBackgroundPaint(Color.white);
    categoryplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinesVisible(true);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    categoryaxis.setLowerMargin(0.0D);
    categoryaxis.setUpperMargin(0.0D);
    categoryaxis.addCategoryLabelToolTip("Type 1", "The first type.");
    categoryaxis.addCategoryLabelToolTip("Type 2", "The second type.");
    categoryaxis.addCategoryLabelToolTip("Type 3", "The third type.");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setLabelAngle(0.0D);
    return jfreechart;
}

From source file:wsattacker.plugin.intelligentdos.ui.helper.ChartHelper.java

public static JFreeChart createDumyChart() {
    final BoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset();

    final CategoryAxis xAxis = new CategoryAxis("Type");
    final NumberAxis yAxis = new NumberAxis("Value");
    yAxis.setAutoRangeIncludesZero(false);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setFillBox(true);//from   w w w.  j  av  a 2s  . co m
    renderer.setMeanVisible(false);
    renderer.setMedianVisible(false);
    // renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    final CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    return new JFreeChart(plot);
}

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());
    }/* w  ww.java  2 s .com*/

    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:soap.ui.stats.OverLaidBarChartFactory.java

public static JFreeChart createDualBarAndLineDiagram(String title, String categoryAxisLabel,
        String valueAxisLabel, CategoryDataset barDiagramDataset, LinkedList lineDiagramDatasets) {
    CategoryPlot plot = new CategoryPlot();
    int inc = 0;/*w ww.j  a  va  2s .c om*/
    BarRenderer barRenderer = null;
    if (barDiagramDataset != null) {
        plot.setDataset(barDiagramDataset);
        barRenderer = new BarRenderer3D();
        barRenderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());
        plot.setRenderer(barRenderer);
        inc = 1;
        plot.setDomainAxis(new CategoryAxis3D(categoryAxisLabel));
        plot.setRangeAxis(new NumberAxis3D(valueAxisLabel));
    } else {
        plot.setDomainAxis(new CategoryAxis(categoryAxisLabel));
        plot.setRangeAxis(new NumberAxis(valueAxisLabel));
    }
    plot.mapDatasetToRangeAxis(0, 0);

    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    CategoryItemRenderer renderers[] = new LineAndShapeRenderer[lineDiagramDatasets.size()];

    for (int i = 0; i < lineDiagramDatasets.size(); i++) {
        CategoryDataset lineDiagramDataset = (CategoryDataset) lineDiagramDatasets.get(i);
        plot.setDataset(i + inc, lineDiagramDataset);
        plot.mapDatasetToRangeAxis(i + inc, 0);
        if (barDiagramDataset != null && i < barDiagramDataset.getRowCount()) {
            renderers[i] = new LineAndShapeRendererMapToBar(barRenderer, i);
        } else {
            renderers[i] = new LineAndShapeRenderer();
        }
        renderers[i].setToolTipGenerator(new StandardCategoryToolTipGenerator());
        renderers[i].setSeriesStroke(0, new BasicStroke(1.5f));
        renderers[i].setSeriesStroke(1, new BasicStroke(1.5f));
        plot.setRenderer(i + inc, renderers[i]);
    }

    CategoryDataset dataset;
    if (lineDiagramDatasets.size() > 0)
        dataset = (CategoryDataset) lineDiagramDatasets.get(0);
    else
        dataset = barDiagramDataset;
    for (int i = 0; i < dataset.getColumnCount(); i++)
        plot.getDomainAxis().addCategoryLabelToolTip(dataset.getColumnKey(i), (String) dataset.getColumnKey(i));

    plot.setRangeGridlinePaint(Color.black);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(title);
    chart.setLegend(new StandardLegend());

    return chart;
}

From source file:com.jaxzin.iraf.demo.CdfInv.java

private static void customizeChart(JFreeChart chart) {
    // Set the transparency of the histogram bars
    chart.getCategoryPlot().setForegroundAlpha(0.5f);

    // Lock the y-axis to 0.0->0.5
    ValueAxis axis = new NumberAxis("Value");
    axis.setAutoRange(true);/*from  w w  w  .  ja  va2  s  .  com*/
    chart.getCategoryPlot().setRangeAxis(axis);
    // Lock the x-axis to -6.0->6.0
    CategoryAxis domainAxis = new CategoryAxis("Probability");
    domainAxis.setTickLabelsVisible(false);
    chart.getCategoryPlot().setDomainAxis(domainAxis);
}

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

private static JFreeChart createChart(MultiValueCategoryDataset multivaluecategorydataset) {
    CategoryPlot categoryplot = new CategoryPlot(multivaluecategorydataset, new CategoryAxis("Category"),
            new NumberAxis("Value"), new ScatterRenderer());
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setDomainGridlinePaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.white);
    categoryplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
    JFreeChart jfreechart = new JFreeChart("ScatterRendererDemo1", categoryplot);
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

From source file:org.shredzone.bullshitcharts.chart.BarChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());/*from   w w w.  j ava  2  s.  c  o  m*/
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    BarRenderer3D renderer = new BarRenderer3D();

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}

From source file:org.shredzone.bullshitcharts.chart.LineChartGenerator.java

@Override
public Plot generate() {
    LineDatasetCreator dataset = new LineDatasetCreator();
    dataset.setTendency(getTendency());/*from w w w  .  jav  a  2 s . c  om*/
    dataset.setNumberOfValues(getResolution());
    dataset.setAmplitude(getAmplitude());

    CategoryAxis catAxis = new CategoryAxis(getValue("x", "Time")); // TODO: i18n
    catAxis.setLowerMargin(0.0d);
    catAxis.setUpperMargin(0.0d);
    catAxis.setTickMarksVisible(false);
    catAxis.setTickLabelsVisible(false);

    ValueAxis valAxis = new NumberAxis(getValue("y", "Value"));
    valAxis.setRange(new Range(0.0d, 1.05d));
    valAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    valAxis.setTickMarksVisible(false);
    valAxis.setTickLabelsVisible(false);

    LineAndShapeRenderer renderer = new LineRenderer3D();
    renderer.setBaseShapesVisible(false);
    //        renderer.setStroke(new BasicStroke(2.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));

    CategoryPlot plot = new CategoryPlot(dataset.generate(), catAxis, valAxis, renderer);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    return plot;
}