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

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

Introduction

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

Prototype

public XYItemRenderer getRenderer() 

Source Link

Document

Returns the renderer for the primary dataset.

Usage

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.PortHeatMapPlotPanel.java

private PortHeatMapPlotPanel(OMS_Collection history, ArrayList<IB_Vertex> includedNodes,
        EnumSet<IB_Depth> includedDepths) {
    super(new BorderLayout());

    // creates the main chart panel, which creates the PortHeatMapDataSet
    // (so all the data has been initialized here, available for all subsequent actions)
    overallDimension = new java.awt.Dimension(900, 500);
    heatPanel = (ChartPanel) createHeatPanel(history, includedNodes, includedDepths);
    heatPanel.setPreferredSize(overallDimension);

    // add the vertical and horizontal crosshairs
    CrosshairOverlay overlay = new CrosshairOverlay();
    TimeXhair = new Crosshair(0);
    TimeXhair.setPaint(TimeSliceColor); // vertical slice (single timestamp) for dataset1, SingleTimeChart plot 1, slider 2, etc
    PortXhair = new Crosshair(0);
    PortXhair.setPaint(PortSliceColor); // horizontal slice (single port) for dataset2, SinglePortChart, slider 1
    overlay.addDomainCrosshair(TimeXhair);
    overlay.addRangeCrosshair(PortXhair);
    heatPanel.addOverlay(overlay);//from   w  w w  . j  av a2 s . c om
    TimeXhair.setLabelVisible(true);
    TimeXhair.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
    TimeXhair.setLabelBackgroundPaint(new Color(255, 255, 0, 100));
    PortXhair.setLabelVisible(true);
    PortXhair.setLabelBackgroundPaint(new Color(255, 255, 0, 100));

    add(heatPanel);

    JPanel PortSliderPanel = new JPanel(new BorderLayout());

    // all ports, single timestamp (right vertical plot) - uses TimeXhair and slider 2 from the horizontal panel (TimeSliderPanel)
    XYSeriesCollection dataset1 = new XYSeriesCollection();
    SingleTimeChart = ChartFactory.createXYLineChart("Vertical Cross-section (all ports single timestamp)",
            PortAxisLabel, UtilizationAxisLabel, dataset1, PlotOrientation.HORIZONTAL, false, false, false);
    XYPlot plot1 = (XYPlot) SingleTimeChart.getPlot();
    plot1.getDomainAxis().setLowerMargin(0.0);
    plot1.getDomainAxis().setUpperMargin(0.0);
    plot1.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    plot1.getRenderer().setSeriesPaint(0, TimeSliceColor);

    // this is the right
    ChartPanel SingleTimeChartPanel = new ChartPanel(SingleTimeChart);
    SingleTimeChartPanel.setMinimumDrawWidth(0);
    SingleTimeChartPanel.setMinimumDrawHeight(0);

    SingleTimeChartPanel.setPreferredSize(new Dimension(200, (int) (overallDimension.getWidth() / 3)));
    ((XYPlot) SingleTimeChart.getPlot()).getRangeAxis().setRange(new Range(0, 1));
    ((XYPlot) SingleTimeChart.getPlot()).getDomainAxis().setRange(new Range(0, 1));

    // this slider panel holds the slider and the Single Time Snapshot of all ports, on the right or EAST (for use with plot2)
    PortSlider = new JSlider(0, 1, 0);
    PortSlider.addChangeListener(this);
    PortSlider.setOrientation(JSlider.VERTICAL);

    PortSliderPanel.add(SingleTimeChartPanel);
    PortSliderPanel.add(PortSlider, BorderLayout.WEST);

    TimeSliderPanel = new JPanel(new BorderLayout());

    // single port, all timestamps (lower horizontal plot) - uses PortXhair and slider 1 from the vertical panel (PortSliderPanel)
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    SinglePortChart = ChartFactory.createXYLineChart("Horizontal Cross-section (single port over time)",
            TimeAxisLabel, UtilizationAxisLabel, dataset2, PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot2 = (XYPlot) SinglePortChart.getPlot();
    plot2.getDomainAxis().setLowerMargin(0.0);
    plot2.getDomainAxis().setUpperMargin(0.0);
    plot2.getRenderer().setSeriesPaint(0, PortSliceColor);

    ChartPanel SinglePortChartPanel = new ChartPanel(SinglePortChart);
    SinglePortChartPanel.setMinimumDrawWidth(0);
    SinglePortChartPanel.setMinimumDrawHeight(0);

    SinglePortChartPanel.setPreferredSize(new Dimension(200, (int) (overallDimension.getHeight() / 3)));
    ((XYPlot) SinglePortChart.getPlot()).getRangeAxis().setRange(new Range(0, 1));
    ((XYPlot) SinglePortChart.getPlot()).getDomainAxis().setRange(new Range(0, 1));

    DepthPanel = new HeatMapDepthPanel(null);
    DepthPanel.setPreferredSize(
            new Dimension((int) (overallDimension.getWidth() / 4), (int) (overallDimension.getHeight() / 3)));
    TimeSliderPanel.add(DepthPanel, BorderLayout.EAST);

    // this slider panel holds the slider and the Single Port for all times, in the BOTTOM (for use with plot1)
    TimeSlider = new JSlider(0, 1, 0);
    TimeSlider.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 200));
    TimeSlider.addChangeListener(this);

    TimeSliderPanel.add(SinglePortChartPanel);
    TimeSliderPanel.add(TimeSlider, BorderLayout.NORTH);
    add(PortSliderPanel, BorderLayout.EAST);
    add(TimeSliderPanel, BorderLayout.SOUTH);
    heatChart.setNotify(true);
}

From source file:org.n52.oxf.render.sos.TimeSeriesChartRenderer4xPhenomenons.java

public JFreeChart renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon) {
    // which observedProperty has been used?:
    ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty");
    if (observedPropertyPS.hasMultipleSpecifiedValues()) {
        observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class);
    } else if (observedPropertyPS.hasSingleSpecifiedValue()) {
        observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() };
    } else {// w ww.  j a v  a2 s .  c  o m
        throw new IllegalArgumentException("no observedProperties found.");
    }

    String[] foiIdArray;
    ParameterShell foiParamShell = paramCon.getParameterShellWithServiceSidedName("featureOfInterest");
    if (foiParamShell.hasMultipleSpecifiedValues()) {
        foiIdArray = foiParamShell.getSpecifiedTypedValueArray(String[].class);
    } else {
        foiIdArray = new String[] { (String) foiParamShell.getSpecifiedValue() };
    }

    ObservationSeriesCollection tuples4FOI = new ObservationSeriesCollection(observationCollection, foiIdArray,
            observedProperties, false);

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            "Date", // x-axis label
            observedProperties[0], // y-axis label
            createDataset(foiIdArray, tuples4FOI, 0), // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // add additional datasets:

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat());

    for (int i = 1; i < observedProperties.length; i++) {
        XYDataset additionalDataset = createDataset(foiIdArray, tuples4FOI, i);
        plot.setDataset(i, additionalDataset);
        plot.setRangeAxis(i, new NumberAxis(observedProperties[i]));
        plot.getRangeAxis(i).setRange((Double) tuples4FOI.getMinimum(i), (Double) tuples4FOI.getMaximum(i));
        plot.mapDatasetToRangeAxis(i, i);
    }

    return chart;
}

From source file:hudson.plugins.codeviation.JavaFileIterableView.java

public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException {
    Lookup lookup = Lookup.getDefault();
    ChartConfProvider provider = null;//from  w  w  w  .  j a  v a 2  s  .  c o  m
    ChartConf conf = getChartConf(req);
    if (lookup != null) {
        for (ChartConfProvider prov : lookup.lookupAll(ChartConfProvider.class)) {
            for (ChartConf c : prov.getChartConfs()) {
                if (c.equals(conf)) {
                    provider = prov;
                }
            }
        }
    }
    if (provider == null) {
        provider = new CountsStatHandler();
        conf = provider.getChartConfs()[0];
    }

    Graph graph = conf.createGraph();
    if (graph == null) {
        getLogger().info("Date:" + getMinDate() + "," + getMaxDate());
        graph = new Statistics(getMinDate(), getMaxDate());
    }
    JavaFileHandler handler = conf.getStatHandler();
    graph.setJavaFileHandler(handler);
    graph.setItemsCount(100);
    handler.init(graph);
    graph.addJavaFiles(getJavaFiles());

    handler.initGraphPaint(conf);
    JFreeChart chart = graph.getChart(conf, true);

    chart.setBackgroundPaint(Color.WHITE);
    chart.setTitle((String) null);
    XYPlot plot = (XYPlot) chart.getPlot();
    //        plot.setDomainGridlinePaint(Color.BLACK);
    //        plot.setRangeGridlinePaint(Color.BLACK);
    //        
    //        plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    //        
    //        plot.setDomainCrosshairVisible(true);
    //        plot.setRangeCrosshairVisible(true);       
    //        
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        //            renderer.setBaseShapesVisible(true);
        ////            renderer.setBaseShapesFilled(true);
        //            renderer.setUseFillPaint(true);
        //            
        //  //          renderer.setSeriesItemLabelsVisible(1, true);
        //            renderer.setUseOutlinePaint(true);
        renderer.setStroke(new BasicStroke(2.0f));
        ////            renderer.getPlot().setRenderer(1, r)getRenderer(1).setStroke();
        ////            renderer.setStroke();
        //            
        //  //          renderer.setS
    }
    //        
    ChartUtil.generateGraph(req, rsp, chart, 400, 400);

}

From source file:org.matsim.contrib.freight.usecases.analysis.LegHistogram.java

private JFreeChart getGraphic(final ModeData modeData, final String modeName) {
    final XYSeriesCollection xyData = new XYSeriesCollection();
    final XYSeries departuresSerie = new XYSeries("departures", false, true);
    final XYSeries arrivalsSerie = new XYSeries("arrivals", false, true);
    final XYSeries onRouteSerie = new XYSeries("en route", false, true);
    int onRoute = 0;
    for (int i = 0; i < modeData.countsDep.length; i++) {
        onRoute = onRoute + modeData.countsDep[i] - modeData.countsArr[i] - modeData.countsStuck[i];
        double hour = i * this.binSize / 60.0 / 60.0;
        departuresSerie.add(hour, modeData.countsDep[i]);
        arrivalsSerie.add(hour, modeData.countsArr[i]);
        onRouteSerie.add(hour, onRoute);
    }// w  w  w .ja va 2 s  .c o  m

    xyData.addSeries(departuresSerie);
    xyData.addSeries(arrivalsSerie);
    xyData.addSeries(onRouteSerie);

    final JFreeChart chart = ChartFactory.createXYStepChart(
            "Leg Histogram, " + modeName + ", it." + this.iteration, "time", "# vehicles", xyData,
            PlotOrientation.VERTICAL, true, // legend
            false, // tooltips
            false // urls
    );

    XYPlot plot = chart.getXYPlot();

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

    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f));
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.gray);
    plot.setDomainGridlinePaint(Color.gray);

    return chart;
}

From source file:com.bt.aloha.sipstone.GenGraph.java

private JFreeChart createCombinedChart() {
    XYDataset xydatasetArray[] = createDataset_TotalCallCreated_CallsPerSecond();
    XYDataset xydataset = xydatasetArray[0];
    final XYDataset percXydataset = xydatasetArray[1];
    JFreeChart jfreechart = ChartFactory.createXYLineChart("SIPStone graph", "Calls", "Call rate", xydataset,
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    NumberAxis numberaxis = new NumberAxis("Avg. Response Time");
    numberaxis.setAutoRangeIncludesZero(false);
    xyplot.setRangeAxis(1, numberaxis);//from  w w w  . j  ava 2 s  .c  om
    xyplot.setDataset(1, createDataset_TotalCallCreated_AvgResponseTime());
    xyplot.mapDatasetToRangeAxis(1, 1);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    xyitemrenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setShapesFilled(true);
    }
    XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer();
    xylineandshaperenderer1.setSeriesPaint(0, Color.black);
    xylineandshaperenderer1.setBaseShapesVisible(true);
    xylineandshaperenderer1.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    xyplot.setRenderer(1, xylineandshaperenderer1);
    NumberAxis timeaxis = (NumberAxis) xyplot.getDomainAxis();
    timeaxis.setAutoRange(true);
    timeaxis.setAxisLineVisible(true);
    LegendTitle legendtitle = new LegendTitle(xyitemrenderer);
    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));

    XYItemRenderer xyrenderer = (XYItemRenderer) xyplot.getRenderer();
    xyrenderer.setBaseItemLabelGenerator(new MyXYItemLabelGenerator(percXydataset));
    xyrenderer.setBaseItemLabelsVisible(true);

    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(compositetitle);
    return jfreechart;
}

From source file:com.att.aro.ui.view.diagnostictab.plot.SpeedThrottlePlot.java

/**
 * @param plot//from w ww .j  av  a  2 s  .c  o m
 * @param seriesDL
 * @param seriesUP
 */
private void setDataPlot(XYPlot plot, XYSeries seriesDL, XYSeries seriesUP) {
    serCollection.addSeries(seriesDL);
    serCollection.addSeries(seriesUP);

    XYStepRenderer renderer = new XYStepRenderer();

    LogAxis rangeAxis = new LogAxis(); // new API 
    rangeAxis.setAutoRange(true);
    rangeAxis.setVisible(false);
    plot.setRangeAxis(rangeAxis);
    plot.setRangePannable(true);
    plot.setRangeCrosshairVisible(true);

    renderer = (XYStepRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    renderer.setSeriesStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);

    renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            StringBuffer displayInfo = new StringBuffer();
            java.lang.Number tempx = dataset.getX(series, item);
            java.lang.Number tempy = dataset.getY(series, item);
            // series 0 -> downstream , stries 1 -> upstream
            String streamInfo = "";
            if (series == 0) {
                streamInfo = ResourceBundleHelper.getMessageString("dlog.collector.option.attenuator.downlink");
            } else {
                streamInfo = ResourceBundleHelper.getMessageString("dlog.collector.option.attenuator.uplink");
            }
            return displayInfo.append("Time: " + tempx + " , " + streamInfo + " : " + tempy + " kbps")
                    .toString();
        }
    });
    plot.setRenderer(renderer);
    plot.setDataset(serCollection);

}

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

/**
 * Creates the demo chart.//from  ww w .ja va 2  s .c  o  m
 * 
 * @return The chart.
 */
protected JFreeChart createChart(XYDataset dataset) {
    JFreeChart chart1 = ChartFactory.createTimeSeriesChart(chartTitle, domainLabel, //"Time of Day", 
            rangeLabel, //"Value",
            dataset, !legendPanelOn, true, false);

    chart1.setBackgroundPaint(Color.white);
    XYPlot plot = chart1.getXYPlot();
    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));

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(false);
    plot.setRangeCrosshairVisible(false);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setBasePaint(Color.black);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    //         setXSummary(dataset); X is time
    return chart1;
}

From source file:atencionurgencia.evolucion.grafic_sVitales.java

private void graficar() {
    final TimeSeriesCollection dataset1 = axisTaFC.createDatasetTA();
    final JFreeChart chart2 = ChartFactory.createTimeSeriesChart("", // chart title
            "HORA", // domain axis label
            "Tensin Arterial - TA (ppm)", // range axis label
            dataset1, // data

            true, // include legend
            true, // tooltips?
            false // URL generator?  Not required...
    );//from   w  w w .  j  av  a  2 s . c om
    chart2.setBackgroundPaint(Color.white);
    final XYPlot plot = chart2.getXYPlot();
    plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
    plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    //        plot.set

    //        
    ////        final CategoryDataset dataset2 = axisTaFC.createDatasetFC();
    ////        plot.setDataset(1, dataset2);
    plot.mapDatasetToRangeAxis(1, 0);
    //        
    //        final DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    //        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    ////        final ValueAxis axis2 = new NumberAxis("Frecuencia Cardiaca - FC (ppm)");
    ////        plot.setRangeAxis(1, axis2);

    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    //        
    //        
    //        
    final ChartPanel chartPanel = new ChartPanel(chart2);
    chartPanel.setPreferredSize(new java.awt.Dimension(444, 358));//[598, 358][444, 358]
    jPanel4.removeAll();
    jPanel4.setLayout(new BorderLayout());
    jPanel4.add(chartPanel, BorderLayout.NORTH);
    jPanel4.repaint();
}

From source file:edu.ucla.stat.SOCR.chart.ChartGenerator.java

protected JFreeChart createQQChart(String title, String xLabel, String yLabel, XYDataset dataset,
        String other) {//from  w ww .  jav  a2 s.c o m

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xLabel, // x axis label
            yLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    // renderer.setShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    //  renderer.setLinesVisible(false);
    renderer.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(1, false);
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(0, true);

    //renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0);
    rangeAxis.setLowerMargin(0);

    // rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0);
    domainAxis.setLowerMargin(0);

    // domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // OPTIONAL CUSTOMISATION COMPLETED.
    //setQQSummary(dataset);    // very confusing   
    return chart;

}

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

/**
 * Creates the demo chart.// www.j a va 2  s  . c o  m
 * 
 * @return The chart.
 */
private JFreeChart createChart() {

    // create some sample data

    final XYSeries series1 = new XYSeries("Something");
    series1.add(0.0, 30.0);
    series1.add(1.0, 10.0);
    series1.add(2.0, 40.0);
    series1.add(3.0, 30.0);
    series1.add(4.0, 50.0);
    series1.add(5.0, 50.0);
    series1.add(6.0, 70.0);
    series1.add(7.0, 70.0);
    series1.add(8.0, 80.0);

    final XYSeriesCollection dataset1 = new XYSeriesCollection();
    dataset1.addSeries(series1);

    final XYSeries series2 = new XYSeries("Something else");
    series2.add(0.0, 5.0);
    series2.add(1.0, 4.0);
    series2.add(2.0, 1.0);
    series2.add(3.0, 5.0);
    series2.add(4.0, 0.0);

    final XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(series2);

    // create the chart

    final JFreeChart result = ChartFactory.createXYLineChart("Tick Label Demo", "Domain Axis 1", "Range Axis 1",
            dataset1, PlotOrientation.VERTICAL, false, true, false);

    result.setBackgroundPaint(Color.white);
    final XYPlot plot = result.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);

    // DOMAIN AXIS 2
    final NumberAxis xAxis2 = new NumberAxis("Domain Axis 2");
    xAxis2.setAutoRangeIncludesZero(false);
    plot.setDomainAxis(1, xAxis2);

    // RANGE AXIS 2
    final DateAxis yAxis1 = new DateAxis("Range Axis 1");
    plot.setRangeAxis(yAxis1);

    final DateAxis yAxis2 = new DateAxis("Range Axis 2");
    plot.setRangeAxis(1, yAxis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    plot.setDataset(1, dataset2);
    plot.mapDatasetToDomainAxis(1, 1);
    plot.mapDatasetToRangeAxis(1, 1);

    return result;
}