Example usage for org.jfree.chart.axis NumberAxis setLabelPaint

List of usage examples for org.jfree.chart.axis NumberAxis setLabelPaint

Introduction

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

Prototype

public void setLabelPaint(Paint paint) 

Source Link

Document

Sets the paint used to draw the axis label and sends an AxisChangeEvent to all registered listeners.

Usage

From source file:ch.zhaw.parallelComputing.view.Plotter.java

/**
 * Generates a plot for comparing to datasets
 * @param title the name of the plot/*  www.  ja  va 2  s  . c  o m*/
 * @param dataset1 the first data set for plotting
 * @param dataset2 the second data set for plotting
 * @return a chart object for displaying or saving as picture
 */
public static JFreeChart plot(String title, XYDataset dataset1, XYDataset dataset2) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(title, // title
            "Date", // x-axis label
            "Input Value", // y-axis label
            dataset1, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    XYPlot plot = chart.getXYPlot();

    Axis axis1 = plot.getRangeAxis(0);
    axis1.setLabelPaint(Color.red);

    NumberAxis axis2 = new NumberAxis("Twitter");
    axis2.setLabelPaint(Color.blue);
    plot.setRangeAxis(1, axis2);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setBaseShapesVisible(false);
    plot.setRenderer(1, renderer);

    return chart;
}

From source file:org.jfree.chart.swt.demo.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart.//  w ww. j av  a2 s  . co  m
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    //axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:cn.edu.thss.iise.bpmdemo.charts.SWTMultipleAxisDemo1.java

/**
 * Creates the demo chart.//from w ww .  j  a  v a  2  s  . c  o m
 *
 * @return The chart.
 */
private static JFreeChart createChart() {

    XYDataset dataset1 = createDataset("Series 1", 100.0, new Day(), 200);

    JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 3", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.setBorderVisible(true);
    chart.setBorderPaint(Color.BLACK);
    TextTitle subtitle = new TextTitle("Four datasets and four range axes.");
    chart.addSubtitle(subtitle);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    XYDataset dataset2 = createDataset("Series 2", 1000.0, new Day(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    // axis3.setPositiveArrowVisible(true);
    plot.setRangeAxis(2, axis3);

    XYDataset dataset3 = createDataset("Series 3", 10000.0, new Day(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4
    NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    XYDataset dataset4 = createDataset("Series 4", 25.0, new Day(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:ucar.unidata.idv.control.chart.HistogramWrapper.java

/**
 * Plot the displayed {@link DataChoice}.
 * /* ww  w . ja v a2  s.c  o m*/
 * @param histoWrapper Cannot be {@code null}.
 */
public static void plotHistogram(HistogramWrapper histoWrapper) {
    XYPlot p = histoWrapper.plot;
    List<DataChoiceWrapper> dcWrappers = histoWrapper.getDataChoiceWrappers();

    try {
        for (int dataSetIdx = 0; dataSetIdx < p.getDatasetCount(); dataSetIdx++) {
            MyHistogramDataset dataset = (MyHistogramDataset) p.getDataset(dataSetIdx);
            dataset.removeAllSeries();
        }

        Hashtable props = new Hashtable();
        props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE);

        for (int paramIdx = 0; paramIdx < dcWrappers.size(); paramIdx++) {
            DataChoiceWrapper wrapper = dcWrappers.get(paramIdx);

            DataChoice dataChoice = wrapper.getDataChoice();
            FlatField data = histoWrapper.getFlatField((FieldImpl) dataChoice.getData(null, props));
            Unit unit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0];
            double[][] samples = data.getValues(false);
            double[] actualValues = histoWrapper.filterData(samples[0],
                    histoWrapper.getTimeValues(samples, data))[0];
            NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit));

            XYItemRenderer renderer;
            if (histoWrapper.stacked) {
                renderer = new StackedXYBarRenderer();
            } else {
                renderer = new XYBarRenderer();
            }
            p.setRenderer(paramIdx, renderer);
            Color c = wrapper.getColor(paramIdx);
            domainAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);

            MyHistogramDataset dataset = new MyHistogramDataset();
            dataset.setType(HistogramType.FREQUENCY);
            dataset.addSeries(dataChoice.getName() + " [" + unit + "]", actualValues, histoWrapper.bins);
            p.setDomainAxis(paramIdx, domainAxis, false);
            p.mapDatasetToDomainAxis(paramIdx, paramIdx);
            p.setDataset(paramIdx, dataset);
        }
    } catch (VisADException | RemoteException e) {
        LogUtil.logException("Error creating data set", e);
    }
}

From source file:org.cyberoam.iview.charts.CustomCategoryAxis.java

/**
 * This method generates JFreeChart instance for 3D Bar chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from uri.
 * @return jfreechart instance with iView Customization.
 *//*from   w  w w . j av  a 2 s  .co m*/
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    JFreeChart chart = null;
    boolean isPDF = false;
    try {
        if (request == null) {
            isPDF = true;
        }
        /*
         * Create data set based on rsw object.
         */
        ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
        ReportColumnBean reportColumnBeanX, reportColumnBeanY = null;

        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBeanX = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        if (reportColumnBeanX.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBeanX.getDataLinkId());
        }

        reportColumnBeanY = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        rsw.beforeFirst();
        int i = 0;
        DecimalFormat placeHolder = new DecimalFormat("00");
        String xData = null;
        String graphurl = "";
        HashMap<Integer, String> urlmap = new HashMap<Integer, String>();
        while (rsw.next()) {
            xData = rsw.getString(reportColumnBeanX.getDbColumnName());
            if (dataLinkBean != null && request != null) {
                //datalink id is non -1 in tblcolumnreport table means another report is avaialble so set url 
                // here multiple url possible bec multiple record so take hashmap and store url. 
                // we have dataset but dataset is occupied.
                graphurl = dataLinkBean.generateURLForChart(rsw, request);
                urlmap.put(new Integer(i), graphurl);
            }
            //dataset second arugument use for bar line of graph and third argument give name of graph
            dataset.addValue(new Long(rsw.getLong(reportColumnBeanY.getDbColumnName())), "",
                    placeHolder.format(i) + xData);
            i++;
        }
        // we define object of CustomURLGeneratorForBarChart and if datalinkid is not -1 then it object define for link
        CustomURLGeneratorForBarChart customURLGeneratorForBarChart = null;
        if (dataLinkBean != null && request != null) {
            customURLGeneratorForBarChart = new CustomURLGeneratorForBarChart(
                    dataLinkBean.generateURLForChart(request), reportColumnBeanX.getDbColumnName());
            customURLGeneratorForBarChart.setUrlMap(urlmap);
        }
        /*
         * Create the jfree chart object.
         */
        String title = isPDF ? reportBean.getTitle() : "";
        chart = ChartFactory.createBarChart3D(title, // chart title
                "", // domain axis label
                "", dataset, // data            
                PlotOrientation.HORIZONTAL, // orientation
                false, // include legend
                true, // tooltips?
                false // URLs?
        );

        /*
         *Setting additional customization to the chart. 
         */
        //Set background color
        chart.setBackgroundPaint(Color.white);
        //Get a reference to the plot for further customisation
        CategoryPlot plot = chart.getCategoryPlot();
        plot.setBackgroundPaint(Color.white);
        plot.setDomainGridlinePaint(Color.white);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.DARK_GRAY);
        plot.setForegroundAlpha(0.8f);
        plot.setDomainGridlineStroke(new BasicStroke(2));
        plot.setOutlineVisible(false);
        plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

        //Set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        if (reportColumnBeanY.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) {
            rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4));
        }
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(false);
        rangeAxis.setLabel(reportColumnBeanY.getColumnName());
        rangeAxis.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 12));
        rangeAxis.setLabelPaint(new Color(35, 139, 199));

        CustomCategoryAxis catAxis = new CustomCategoryAxis();
        catAxis.setTickLabelFont(new Font("Arial", Font.CENTER_BASELINE, 10));
        catAxis.setTickMarksVisible(false);
        catAxis.setAxisLineVisible(false);
        catAxis.setLabel(reportColumnBeanX.getColumnName());
        catAxis.setLabelFont(new Font("Arial", Font.CENTER_BASELINE, 12));
        catAxis.setLabelPaint(new Color(35, 139, 199));
        catAxis.setLabelFormat(reportColumnBeanX.getColumnFormat());

        plot.setDomainAxis(catAxis);

        //Set custom color for the chart.         
        CategoryItemRenderer renderer = new CustomRenderer(new Paint[] { new Color(254, 211, 41),
                new Color(243, 149, 80), new Color(199, 85, 82), new Color(181, 105, 152),
                new Color(69, 153, 204), new Color(155, 212, 242), new Color(52, 172, 100),
                new Color(164, 212, 92), new Color(177, 155, 138), new Color(149, 166, 141) });

        plot.setRenderer(renderer);

        BarRenderer renderer2 = (BarRenderer) plot.getRenderer();
        renderer2.setDrawBarOutline(false);
        renderer2.setBaseItemLabelsVisible(true);
        renderer2.setMaximumBarWidth(0.04);

        if (dataLinkBean != null && request != null) {
            renderer.setBaseItemURLGenerator(customURLGeneratorForBarChart);
            //renderer.setBaseItemURLGenerator(new CustomURLGeneratorForBarChart(dataLinkBean.generateURLForChart(request),reportColumnBeanX.getDbColumnName()));
        }
        renderer.setBaseToolTipGenerator(new CustomToolTipGenerator());
        renderer.setBaseToolTipGenerator(new CustomToolTipGenerator());
        renderer.setBaseToolTipGenerator(
                new CustomToolTipGenerator("{2} " + reportColumnBeanY.getColumnName()));
    } catch (Exception e) {
        CyberoamLogger.appLog.debug("Bar3D.e:" + e, e);
    }
    return chart;
}

From source file:no.met.jtimeseries.marinogram.MarinogramPressurePlot.java

private XYPlot createPlot(TimeZone timezone, boolean plotPressure) {
    ChartPlotter plotter = null;/*  w w  w .j  av a 2  s .c  om*/
    if (plotPressure) {
        plotter = new ChartPlotter();
        // default setting
        plotter.setHeight(this.getHeight());
        plotter.setWidth(this.getWidth());
        plotter.setPlotDefaultProperties("", "");
        NumberPhenomenon pressure = getLocationForecastDataModel()
                .getPhenomenen(PhenomenonName.Pressure.toString(), NumberPhenomenon.class);
        List<Date> shortTermTime = pressure.getTime();
        Color pressureColor = new Color(11, 164, 42);

        PlotStyle.Builder pressureStyleBuilder = new PlotStyle.Builder(
                messages.getString("parameter.pressure") + " (hPa)");
        PlotStyle plotStyle = pressureStyleBuilder.spline(SplineStyle.HYBRID).ticks(4).difference(50.0d)
                .seriesColor(pressureColor).labelColor(pressureColor).build();
        plotter.addLineChart(TimeBase.SECOND, pressure, plotStyle);
        //plotter.formalizeRangeAxisWithMargins(plotter.getRangeAxisIndex() - 1, 950, 1050);

        double tick = (pressure.getMaxValue() - pressure.getMinValue()) / 2;
        tick = Math.ceil(tick / 10) * 10;
        double lowBound = Math.floor(pressure.getMinValue() / (tick)) * (tick);
        lowBound = lowBound - tick / 2;
        double upperBound = lowBound + tick * 4;

        //replicate the range axis 
        NumberAxis referenceAxis = (NumberAxis) plotter.getPlot().getRangeAxis();
        referenceAxis.setTickUnit(new NumberTickUnit(tick));
        referenceAxis.setLowerBound(lowBound);
        referenceAxis.setUpperBound(upperBound);
        NumberAxis numberAxis = new NumberAxis();
        numberAxis.setLabelPaint(pressureColor);
        numberAxis.setTickLabelPaint(referenceAxis.getTickLabelPaint());
        //numberAxis.setLowerMargin(ChartPlotter.LOWER_PLOT_MARGIN);
        numberAxis.setRange(referenceAxis.getLowerBound(), referenceAxis.getUpperBound());
        numberAxis.setTickUnit(referenceAxis.getTickUnit());
        //numberAxis.setRangeWithMargins(950, 1050);
        plotter.getPlot().setRangeAxis(1, numberAxis);

        //first set domain date format and then add hour based domain grid lines
        //TODO: wrap this inside the addHourBasedDomainGridLines for simplicity
        Date minDate = shortTermTime.get(0);
        Date maxDate = shortTermTime.get(shortTermTime.size() >= 48 ? 48 : shortTermTime.size() - 1);
        plotter.setDomainRange(minDate, maxDate);
        plotter.setDomainDateFormat(timezone, "HH");
        plotter.getPlot().setOutlineVisible(true);
        //set domain range after (must) plot all the data
        plotter.addHourBasedDomainGridLines();
        //invisible domain axis
        plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);
        // add markers
        plotter.addDomainMarkers(shortTermTime, timezone, locale);

    }

    return plotter.getPlot();

}

From source file:no.met.jtimeseries.marinogram.MarinogramTemperaturePlot.java

private void plotTemperature(ChartPlotter plotter, NumberPhenomenon temperature, BasicStroke stroke,
        Color color, String label, boolean isThresholdLine) {
    // number axis to be used for wind speed plot
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(color);
    numberAxis.setTickLabelPaint(color);
    numberAxis.setLabel(messages.getString("parameter.temperature") + " (\u00B0 C)");
    PlotStyle plotStyle = new PlotStyle.Builder(label).ticks(6).stroke(stroke).seriesColor(color)
            .plusDegreeColor(color).labelColor(new Color(240, 28, 28)).spline(SplineStyle.HYBRID)
            .numberAxis(numberAxis).build();

    if (isThresholdLine)
        plotter.addThresholdLineChart(TimeBase.SECOND, temperature, plotStyle);
    else/*w  w  w  .  j a v  a  2 s  .  c  om*/
        plotter.addLineChart(TimeBase.SECOND, temperature, plotStyle);
}

From source file:com.thalesgroup.hudson.plugins.cccc.CcccChartBuilder.java

protected JFreeChart createGraph() {

    JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, "Number of modules",
            buildDataset(action), PlotOrientation.VERTICAL, true, false, true);

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setOutlinePaint(null);/*from   w w w  .  j av  a2s.  com*/
    plot.setForegroundAlpha(0.8f);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.black);

    CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
    plot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    domainAxis.setCategoryMargin(0.0);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // crop extra space around the graph
    plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

    CategoryItemRenderer firstRender = new DefaultCategoryItemRenderer();
    CcccAreaRenderer renderer = new CcccAreaRenderer(action.getUrlName());
    plot.setRenderer(firstRender);

    //Second
    NumberAxis axis2 = new NumberAxis("Lines of Code");
    axis2.setLabelPaint(Color.BLUE);
    axis2.setAxisLinePaint(Color.BLUE);
    axis2.setTickLabelPaint(Color.BLUE);
    CategoryPlot categoryPlot = chart.getCategoryPlot();
    categoryPlot.setRangeAxis(1, axis2);
    //CategoryAxis categoryAxis = categoryPlot.getDomainAxis();
    categoryPlot.setDataset(1, buildDataset2(action));
    categoryPlot.mapDatasetToRangeAxis(1, 1);
    CategoryItemRenderer rendu = new DefaultCategoryItemRenderer();
    rendu.setBasePaint(Color.BLUE);
    categoryPlot.setRenderer(1, rendu);

    //Third
    NumberAxis axis3 = new NumberAxis("McCabe's Cyclomatic Number");
    axis3.setLabelPaint(Color.GREEN);
    axis3.setAxisLinePaint(Color.GREEN);
    axis3.setTickLabelPaint(Color.GREEN);
    CategoryPlot categoryPlot3 = chart.getCategoryPlot();
    categoryPlot3.setRangeAxis(2, axis3);
    categoryPlot3.setDataset(2, buildDataset3(action));
    categoryPlot3.mapDatasetToRangeAxis(2, 2);
    categoryPlot3.mapDatasetToDomainAxis(2, 0);
    CategoryItemRenderer rendu3 = new DefaultCategoryItemRenderer();
    rendu3.setBasePaint(Color.GREEN);
    categoryPlot3.setRenderer(2, rendu3);

    return chart;
}

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

/**
 * Creates the demo chart./*from w w  w. jav  a2s . c o  m*/
 * 
 * @return The chart.
 */
private JFreeChart createChart() {

    final XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);

    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Multiple Axis Demo 1", "Time of Day",
            "Primary Range Axis", dataset1, true, true, false);

    chart.setBackgroundPaint(Color.white);
    chart.addSubtitle(new TextTitle("Four datasets and four range axes."));
    final XYPlot plot = chart.getXYPlot();
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPaint(Color.black);

    // AXIS 2
    final NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setAutoRangeIncludesZero(false);
    axis2.setLabelPaint(Color.red);
    axis2.setTickLabelPaint(Color.red);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

    final XYDataset dataset2 = createDataset("Series 2", 1000.0, new Minute(), 170);
    plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    renderer2.setSeriesPaint(0, Color.red);
    plot.setRenderer(1, renderer2);

    // AXIS 3
    final NumberAxis axis3 = new NumberAxis("Range Axis 3");
    axis3.setLabelPaint(Color.blue);
    axis3.setTickLabelPaint(Color.blue);
    plot.setRangeAxis(2, axis3);

    final XYDataset dataset3 = createDataset("Series 3", 10000.0, new Minute(), 170);
    plot.setDataset(2, dataset3);
    plot.mapDatasetToRangeAxis(2, 2);
    XYItemRenderer renderer3 = new StandardXYItemRenderer();
    renderer3.setSeriesPaint(0, Color.blue);
    plot.setRenderer(2, renderer3);

    // AXIS 4        
    final NumberAxis axis4 = new NumberAxis("Range Axis 4");
    axis4.setLabelPaint(Color.green);
    axis4.setTickLabelPaint(Color.green);
    plot.setRangeAxis(3, axis4);

    final XYDataset dataset4 = createDataset("Series 4", 25.0, new Minute(), 200);
    plot.setDataset(3, dataset4);
    plot.mapDatasetToRangeAxis(3, 3);

    XYItemRenderer renderer4 = new StandardXYItemRenderer();
    renderer4.setSeriesPaint(0, Color.green);
    plot.setRenderer(3, renderer4);

    return chart;
}

From source file:de.suse.swamp.modules.scheduledjobs.Statistics.java

/**
 * Generating the graphs that show the amount of running finished wfs over the time.
 *//* www .j  av a2s  .  c om*/
protected void generateWorkflowGraph(String templateName, Date startDate, Date endDate) throws Exception {
    List stats = StatisticStorage.loadStats(templateName, startDate, endDate);
    // only generate if we have stats: 
    if (stats != null && stats.size() > 0) {
        TimeSeriesCollection dataset = new TimeSeriesCollection();
        TimeSeriesCollection avgdataset = new TimeSeriesCollection();
        TimeSeries serie = new TimeSeries("running workflows", Day.class);
        TimeSeries avgserie = new TimeSeries("average age", Day.class);
        for (Iterator datait = stats.iterator(); datait.hasNext();) {
            Dbstatistics statisticItem = (Dbstatistics) datait.next();
            serie.addOrUpdate(new Day(statisticItem.getDate()), statisticItem.getRunningcount());
            avgserie.addOrUpdate(new Day(statisticItem.getDate()), statisticItem.getAvgage() / (3600 * 24));
        }
        dataset.addSeries(serie);
        avgdataset.addSeries(avgserie);

        JFreeChart chart = ChartFactory.createTimeSeriesChart("Running " + templateName + " workflows", "Date",
                "running workflows", dataset, false, false, false);

        // modify chart appearance
        chart.setBackgroundImageAlpha(0.5f);
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.getRangeAxis().setLabelPaint(Color.blue);

        // add the second line: 
        final NumberAxis axis2 = new NumberAxis("Avg. age in days");
        axis2.setLabelPaint(Color.red);
        plot.setRangeAxis(1, axis2);
        plot.setDataset(1, avgdataset);
        plot.mapDatasetToRangeAxis(1, 1);

        final XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
        renderer2.setDrawOutlines(false);
        renderer2.setDrawSeriesLineAsPath(true);
        renderer2.setBaseShapesVisible(false);
        plot.setRenderer(1, renderer2);

        File image = new File(statPath + fs + templateName + ".png");
        if (image.exists())
            image.delete();
        try {
            ChartUtilities.saveChartAsPNG(image, chart, 750, 200);
        } catch (Exception e) {
            Logger.ERROR("Error generating graph for " + templateName + ", e: " + e.getMessage());
            e.printStackTrace();
            throw e;
        }
    }
}