Example usage for org.jfree.chart.plot XYPlot setDataset

List of usage examples for org.jfree.chart.plot XYPlot setDataset

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot setDataset.

Prototype

public void setDataset(int index, XYDataset dataset) 

Source Link

Document

Sets a dataset for the plot and sends a change event to all registered listeners.

Usage

From source file:Methods.CalculusBisection.java

public static ChartPanel createChartBisection(XYDataset datasetFunction) {// Method that populates and returns a Chart Pannel object, uses an entering paramether for the equation dataset and a global variable for the iteration points data set 

    datasetPointsBisection();/*from  w w w . j  a v a 2s  .  c  o m*/

    JFreeChart chart = ChartFactory.createXYLineChart("Equation Chart", "X Axys", "Y Axys", datasetFunction,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();//declaring a renderer used to plot more than one datatset on the table

    plot.setDataset(1, datasetPoints);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(1, renderer);

    return new ChartPanel(chart);

}

From source file:org.hxzon.demo.jfreechart.DatasetVisibleDemo3.java

private static JFreeChart createTimeSeriesChart() {
    XYDataset dataset1 = createDataset1();
    //DomainAxis/*  w ww  .  j  a  va2 s . c o m*/
    DateAxis timeAxis = new DateAxis("");
    timeAxis.setLowerMargin(0.02); // reduce the default margins
    timeAxis.setUpperMargin(0.02);
    timeAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy"));
    //RangeAxis
    NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    NumberAxis valueAxis2 = new NumberAxis("");
    valueAxis2.setAutoRangeIncludesZero(false); // override default
    //        valueAxis.setDefaultAutoRange(new Range(100, 1150));
    //Renderer
    XYToolTipGenerator toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    renderer.setBaseToolTipGenerator(toolTipGenerator);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawSeriesLineAsPath(true);
    XYDataset dataset2 = createDataset2();
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    //Plot
    XYPlot plot = new XYPlot(dataset1, timeAxis, valueAxis, null);
    plot.setRenderer(renderer);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);
    plot.setRangeAxis(1, valueAxis2);
    plot.mapDatasetToRangeAxis(1, 1);
    plot.setBackgroundPaint(plotBackgroundPaint);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    //        plot.setRangePannable(true);
    //chart
    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    chart.setBackgroundPaint(Color.white);
    valueAxis.setAutoRange(false);
    timeAxis.setAutoRange(false);
    return chart;
}

From source file:Methods.CalculusNewtonRaphson.java

public static ChartPanel createChartNewtonRapson(XYDataset datasetFunction) {// Method that populates and returns a Chart Pannel object, uses an entering paramether for the equation dataset and a global variable for the iteration points data set 

    datasetPointsNewtonRapson();/*from  www  .  ja  va 2s  .com*/
    JFreeChart chart = ChartFactory.createXYLineChart("Equation Chart", "X Axys", "Y Axys", datasetFunction,
            PlotOrientation.VERTICAL, true, true, false);//creating a object table wich takes the methods arguments as a dataset

    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();//declaring a renderer used to plot more than one datatset on the table

    plot.setDataset(1, datasetPoints);
    renderer.setSeriesLinesVisible(1, false);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(1, renderer);

    return new ChartPanel(chart);

}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset2006();
    XYDataset xydataset1 = createDataset2007();
    DateAxis dateaxis = new DateAxis("Date");
    Month month = new Month(1, 2007);
    Month month1 = new Month(12, 2007);
    dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond());
    dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM"));
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer();
    xylineandshaperenderer.setUseFillPaint(true);
    xylineandshaperenderer.setBaseFillPaint(Color.white);
    xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer);
    xyplot.setDomainPannable(true);//from ww w  . j a v  a2  s  . c  o m
    xyplot.setRangePannable(true);
    DateAxis dateaxis1 = new DateAxis();
    dateaxis1.setVisible(false);
    xyplot.setDomainAxis(1, dateaxis1);
    xyplot.setDataset(1, xydataset);
    xyplot.mapDatasetToDomainAxis(1, 1);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.blue);
    xylineandshaperenderer1.setUseFillPaint(true);
    xylineandshaperenderer1.setBaseFillPaint(Color.white);
    xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}",
            new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00")));
    xyplot.setRenderer(1, xylineandshaperenderer1);
    JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot);
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(true);
    DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis();
    dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    ChartUtilities.applyCurrentTheme(jfreechart);
    return jfreechart;
}

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

public static JPanel createDemoPanel() {
    TimeSeries timeseries = new TimeSeries("Annual");
    timeseries.add(new Year(1998), 80D);
    timeseries.add(new Year(1999), 85D);
    timeseries.add(new Year(2000), 87.599999999999994D);
    TimeSeriesCollection dataset1 = new TimeSeriesCollection(timeseries);
    TimeSeries timeseries1 = new TimeSeries("Monthly A");
    timeseries1.add(new Month(7, 2000), 85.799999999999997D);
    timeseries1.add(new Month(8, 2000), 85.799999999999997D);
    timeseries1.add(new Month(9, 2000), 85.799999999999997D);
    timeseries1.add(new Month(10, 2000), 86.5D);
    timeseries1.add(new Month(11, 2000), 86.5D);
    timeseries1.add(new Month(12, 2000), 86.5D);
    timeseries1.add(new Month(1, 2001), 87.700000000000003D);
    timeseries1.add(new Month(2, 2001), 87.700000000000003D);
    timeseries1.add(new Month(3, 2001), 87.700000000000003D);
    timeseries1.add(new Month(4, 2001), 88.5D);
    timeseries1.add(new Month(5, 2001), 88.5D);
    timeseries1.add(new Month(6, 2001), 88.5D);
    timeseries1.add(new Month(7, 2001), 90D);
    timeseries1.add(new Month(8, 2001), 90D);
    timeseries1.add(new Month(9, 2001), 90D);
    timeseries1.add(new Month(10, 2001), 90D);
    timeseries1.add(new Month(11, 2001), 90D);
    timeseries1.add(new Month(12, 2001), 90D);
    timeseries1.add(new Month(1, 2002), 90D);
    timeseries1.add(new Month(2, 2002), 90D);
    timeseries1.add(new Month(3, 2002), 90D);
    timeseries1.add(new Month(4, 2002), 90D);
    timeseries1.add(new Month(5, 2002), 90D);
    timeseries1.add(new Month(6, 2002), 90D);
    TimeSeries timeseries2 = new TimeSeries("Monthly B");
    timeseries2.add(new Month(7, 2000), 83.799999999999997D);
    timeseries2.add(new Month(8, 2000), 83.799999999999997D);
    timeseries2.add(new Month(9, 2000), 83.799999999999997D);
    timeseries2.add(new Month(10, 2000), 84.5D);
    timeseries2.add(new Month(11, 2000), 84.5D);
    timeseries2.add(new Month(12, 2000), 84.5D);
    timeseries2.add(new Month(1, 2001), 85.700000000000003D);
    timeseries2.add(new Month(2, 2001), 85.700000000000003D);
    timeseries2.add(new Month(3, 2001), 85.700000000000003D);
    timeseries2.add(new Month(4, 2001), 86.5D);
    timeseries2.add(new Month(5, 2001), 86.5D);
    timeseries2.add(new Month(6, 2001), 86.5D);
    timeseries2.add(new Month(7, 2001), 88D);
    timeseries2.add(new Month(8, 2001), 88D);
    timeseries2.add(new Month(9, 2001), 88D);
    timeseries2.add(new Month(10, 2001), 88D);
    timeseries2.add(new Month(11, 2001), 88D);
    timeseries2.add(new Month(12, 2001), 88D);
    timeseries2.add(new Month(1, 2002), 88D);
    timeseries2.add(new Month(2, 2002), 88D);
    timeseries2.add(new Month(3, 2002), 88D);
    timeseries2.add(new Month(4, 2002), 88D);
    timeseries2.add(new Month(5, 2002), 88D);
    timeseries2.add(new Month(6, 2002), 88D);
    TimeSeriesCollection dataset21 = new TimeSeriesCollection();
    dataset21.addSeries(timeseries1);/*from  w  w w.  java2  s . c om*/
    dataset21.addSeries(timeseries2);
    TimeSeries timeseries3 = new TimeSeries("XXX");
    timeseries3.add(new Month(7, 2000), 81.5D);
    timeseries3.add(new Month(8, 2000), 86D);
    timeseries3.add(new Month(9, 2000), 82D);
    timeseries3.add(new Month(10, 2000), 89.5D);
    timeseries3.add(new Month(11, 2000), 88D);
    timeseries3.add(new Month(12, 2000), 88D);
    timeseries3.add(new Month(1, 2001), 90D);
    timeseries3.add(new Month(2, 2001), 89.5D);
    timeseries3.add(new Month(3, 2001), 90.200000000000003D);
    timeseries3.add(new Month(4, 2001), 90.599999999999994D);
    timeseries3.add(new Month(5, 2001), 87.5D);
    timeseries3.add(new Month(6, 2001), 91D);
    timeseries3.add(new Month(7, 2001), 89.700000000000003D);
    timeseries3.add(new Month(8, 2001), 87D);
    timeseries3.add(new Month(9, 2001), 91.200000000000003D);
    timeseries3.add(new Month(10, 2001), 84D);
    timeseries3.add(new Month(11, 2001), 90D);
    timeseries3.add(new Month(12, 2001), 92D);
    TimeSeriesCollection dataset22 = new TimeSeriesCollection(timeseries3);
    //
    XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0.00")));
    XYPlot plot1 = new XYPlot(dataset1, new DateAxis("Date"), null, renderer1);
    //
    XYAreaRenderer renderer21 = new XYAreaRenderer();
    XYPlot plot2 = new XYPlot(dataset21, new DateAxis("Date"), null, renderer21);
    StandardXYItemRenderer renderer22 = new StandardXYItemRenderer(3);
    renderer22.setBaseShapesFilled(true);
    plot2.setDataset(1, dataset22);
    plot2.setRenderer(1, renderer22);
    plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    //
    NumberAxis valueAxis = new NumberAxis("Value");
    valueAxis.setAutoRangeIncludesZero(false);
    CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(valueAxis);
    combinedPlot.add(plot1, 1);
    combinedPlot.add(plot2, 4);
    //chart
    JFreeChart jfreechart = new JFreeChart("Sample Combined Plot", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot,
            true);
    ChartPanel chartpanel = new ChartPanel(jfreechart);
    chartpanel.setPreferredSize(new Dimension(500, 270));
    chartpanel.addChartMouseListener(new ChartMouseListener() {

        public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
            System.out.println(chartmouseevent.getEntity());
        }

        public void chartMouseMoved(ChartMouseEvent chartmouseevent) {
            System.out.println(chartmouseevent.getEntity());
        }

    });
    return chartpanel;
}

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

private static JFreeChart createChart() {
    IntervalXYDataset dataset1 = createDataset1();
    XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    DateAxis domainAxis = new DateAxis("Date");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    NumberAxis valueAxis = new NumberAxis("Value");
    XYPlot plot = new XYPlot(dataset1, domainAxis, valueAxis, renderer1);
    XYDataset dataset2 = createDataset2();
    StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, renderer2);//from  www . j  ava  2s  .c o  m
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    return new JFreeChart("Overlaid XYPlot Demo 1", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java

protected static XYPlot createXYPlot(XYDataset dataset, Color[] colors) {
    // break up into two datasets, one for bars one for lines
    //LinkedList lines =new LinkedList();
    //LinkedList bars = new LinkedList();
    XYDataset seriesLines = new XYSeriesCollection();
    XYDataset seriesBars = new XYSeriesCollection();
    ((XYSeriesCollection) seriesBars).setIntervalWidth(0.0);

    if (dataset instanceof XYSeriesCollection) {
        while (0 < dataset.getSeriesCount()) {
            XYSeries s = ((XYSeriesCollection) dataset).getSeries(0);
            ((XYSeriesCollection) dataset).removeSeries(0);
            Comparable key = s.getKey();
            boolean lines = false;
            if (key instanceof String)
                lines = ((String) key).startsWith("-");
            if (lines)
                ((XYSeriesCollection) seriesLines).addSeries(s);
            else/*from  w w w  .  ja v a2  s. c  om*/
                ((XYSeriesCollection) seriesBars).addSeries(s);
        }
    } else {
        seriesBars = dataset;
    }

    NumberAxis axisDomain = new NumberAxis();
    axisDomain.setAutoRange(true);
    axisDomain.setAutoRangeIncludesZero(false);
    //      axisDomain.setRange(400.0, 1600.0);
    // NOTE: zooming in too far kills the chart, prevent this
    axisDomain.addChangeListener(new AxisChangeListener() {
        public void axisChanged(AxisChangeEvent event) {
            NumberAxis axis = (NumberAxis) event.getSource();
            Range range = axis.getRange();
            if (range.getLength() < 2.0) {
                //_log.info("AxisChangeListener " + range.getLength() + " " + range.toString());
                double middle = range.getLowerBound() + range.getLength() / 2.0;
                axis.setRange(new Range(middle - 1.1, middle + 1.1));
            }
        }
    });

    NumberAxis axisRange = new NumberAxis();
    axisRange.setAutoRange(true);
    axisRange.setAutoRangeIncludesZero(true);

    XYToolTipGenerator toolTipGenerator = new XYToolTipGenerator() {
        public String generateToolTip(XYDataset xyDataset, int s, int i) {
            double X = Math.round(xyDataset.getXValue(s, i) * 1000.0) / 1000.0;
            double Y = Math.round(xyDataset.getYValue(s, i) * 1000.0) / 1000.0;
            return "(" + X + ", " + Y + ")";
        }
    };

    XYBarRenderer barRenderer = new XYBarRenderer();
    //dhmay adding 2009/09/14.  As of jfree 1.0.13, shadows on by default        
    barRenderer.setShadowVisible(false);

    //dhmay adding for jfreechart 1.0.6 upgrade.  If this isn't here, we get a
    //nullPointerException in XYBarRenderer.drawItemLabel
    barRenderer.setBaseItemLabelGenerator(new NullLabelGenerator());

    barRenderer.setSeriesItemLabelsVisible(0, true);
    barRenderer.setBaseToolTipGenerator(toolTipGenerator);

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    lineRenderer.setBaseToolTipGenerator(toolTipGenerator);

    XYPlot xy = new XYPlot(null, axisDomain, axisRange, null);

    int ds = 0;
    if (seriesLines.getSeriesCount() > 0) {
        xy.setDataset(ds, seriesLines);
        xy.setRenderer(ds, lineRenderer);
        xy.mapDatasetToRangeAxis(ds, 0);
        ds++;
        for (int i = 0; i < seriesLines.getSeriesCount(); i++) {
            Comparable key = ((XYSeriesCollection) seriesLines).getSeriesKey(i);
            boolean lines = false;
            if (key instanceof String)
                lines = ((String) key).startsWith("-");
            lineRenderer.setSeriesLinesVisible(i, lines);
            lineRenderer.setSeriesShapesVisible(i, !lines);
        }
    }
    if (seriesBars.getSeriesCount() > 0) {
        xy.setDataset(ds, seriesBars);
        xy.setRenderer(ds, barRenderer);
        xy.mapDatasetToRangeAxis(ds, 0);
        ds++;
    }

    setColors(xy, colors);

    return xy;
}

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

private static JFreeChart createChart() {
    XYDataset xydataset = createDataset1();
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Annotation Demo 2", "Date", "Price Per Unit",
            xydataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    NumberAxis numberaxis1 = new NumberAxis("Secondary");
    numberaxis1.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis1);
    xyplot.setDataset(1, createDataset2());
    xyplot.mapDatasetToRangeAxis(1, 1);/* w w w.ja va 2 s  .  c  o  m*/
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseShapesFilled(true);
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Annotation 1 (2.0, 167.3)", 2D,
            167.30000000000001D, -0.78539816339744828D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
    xypointerannotation.setPaint(Color.red);
    xypointerannotation.setArrowPaint(Color.red);
    xylineandshaperenderer.addAnnotation(xypointerannotation);
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true);
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation("Annotation 2 (15.0, 613.2)", 15D,
            613.20000000000005D, 1.5707963267948966D);
    xypointerannotation1.setTextAnchor(TextAnchor.TOP_CENTER);
    xylineandshaperenderer1.addAnnotation(xypointerannotation1);
    xyplot.setRenderer(1, xylineandshaperenderer1);
    LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer);
    LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(2000D, 0.0D));
    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:net.commerce.zocalo.freechart.ChartGenerator.java

public static JFreeChart createCustomXYStepAreaChart(TimePeriodValuesCollection top,
        TimePeriodValuesCollection bottom) {
    DateAxis xAxis = new DateAxis(null);
    NumberAxis yAxis = new NumberAxis("price");
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
    yAxis.setUpperBound(100);//from   ww  w .  j  av  a2s  .c  om
    yAxis.setLowerBound(0.0);

    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setDataset(0, top);
    plot.setDataset(1, bottom);
    XYStepAreaRenderer bottomRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null);
    XYStepAreaRenderer topRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null);
    topRenderer.setRangeBase(1.0);
    topRenderer.setSeriesPaint(0, new Color(204, 255, 153));
    bottomRenderer.setSeriesPaint(0, new Color(51, 255, 204));
    plot.setRenderer(bottomRenderer);
    plot.setRenderer(1, topRenderer);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}

From source file:net.sf.jsfcomp.chartcreator.utils.ChartAxisUtils.java

public static void createXYSeriesAxis(JFreeChart chart, ChartAxisData chartAxisData, int axisIndex) {
    ValueAxis axis = null;//ww  w.j a v  a2 s.  c  o m
    if (chartAxisData.getType() != null) {
        if (chartAxisData.getType().equals("number"))
            axis = createNumberAxis(chart, chartAxisData);
        else if (chartAxisData.getType().equals("date"))
            axis = createDateAxis(chart, chartAxisData);

        if (chartAxisData.getTickLabelFontSize() > 0) {
            Font tickFont = CategoryAxis.DEFAULT_TICK_LABEL_FONT
                    .deriveFont(chartAxisData.getTickLabelFontSize());
            axis.setTickLabelFont(tickFont);
        }

        axis.setTickLabelsVisible(chartAxisData.isTickLabels());
        axis.setTickMarksVisible(chartAxisData.isTickMarks());
        axis.setVerticalTickLabels(chartAxisData.isVerticalTickLabels());
    }

    XYPlot plot = chart.getXYPlot();
    if (chartAxisData.isDomain()) {
        plot.setDomainAxis(plot.getDomainAxisCount() - 1, axis);
    } else {
        plot.setRangeAxis(axisIndex, axis);
        XYDataset dataset = (XYDataset) chartAxisData.getDatasource();
        plot.setRenderer(axisIndex, new StandardXYItemRenderer());
        plot.setDataset(axisIndex, dataset);
        plot.mapDatasetToRangeAxis(axisIndex, axisIndex);
    }

    setXYSeriesAxisColors(chartAxisData, plot.getRenderer(axisIndex));
}