Java Code Examples for org.jfree.chart.renderer.xy.XYItemRenderer#setSeriesPaint()

The following examples show how to use org.jfree.chart.renderer.xy.XYItemRenderer#setSeriesPaint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CurveGraphPanel.java    From EccPlayground with Apache License 2.0 6 votes vote down vote up
public static CurveGraphPanel getInstance() {
    if (INSTANCE == null) {
        eccSeries = new XYSeries("ecc", false);
        XYSeriesCollection dataset = new XYSeriesCollection();
        dataset.addSeries(eccSeries);

        JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, dataset, PlotOrientation.VERTICAL,
                false, true, false);

        INSTANCE = new CurveGraphPanel(chart);

        XYItemRenderer renderer = chart.getXYPlot().getRenderer();
        renderer.setSeriesPaint(2, Color.BLACK);
    }
    return INSTANCE;
}
 
Example 2
Source File: MultipleAxisChart.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void finish(java.awt.Dimension preferredSize) {
  ChartUtilities.applyCurrentTheme(chart);

  XYPlot plot = (XYPlot) chart.getPlot();
  for (int i = 0; i < axisNum; i++) {
    XYItemRenderer renderer = plot.getRenderer(i);
    if (renderer == null)
      continue;

    renderer.setSeriesPaint(0, colors[i]);

    ValueAxis axis = plot.getRangeAxis(i);
    axis.setLabelPaint(colors[i]);
    axis.setTickLabelPaint(colors[i]);
  }

  ChartPanel chartPanel = new ChartPanel(chart);
  chartPanel.setPreferredSize(preferredSize);
  chartPanel.setDomainZoomable(true);
  chartPanel.setRangeZoomable(true);
}
 
Example 3
Source File: JRFillChart.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The series colors set in the main plot of a multiple axis chart are used for
 * all the rendered charts in the plot.  This is a problem with multiple line
 * charts, using different scales and thus different axis.  All the lines will
 * be drawn using the first series color (since they are the first series for that
 * rendered) and it will be impossible to tell them apart.
 * <br>
 * For this reason we interpret series colors for charts included in a multiple
 * axis chart as specify absolute series colors for that renderer.
 *
 * @param renderer the renderer of the chart being created
 * @param jrPlot the Jasper view of that plot
 */
private void configureAxisSeriesColors(XYItemRenderer renderer, JRChartPlot jrPlot)
{
	SortedSet<JRSeriesColor> seriesColors = jrPlot.getSeriesColors();

	if (seriesColors != null)
	{
		Iterator<JRSeriesColor> iter = seriesColors.iterator();
		while (iter.hasNext())
		{
			JRSeriesColor seriesColor = iter.next();
			renderer.setSeriesPaint(seriesColor.getSeriesOrder(), seriesColor.getColor());
		}
	}
}
 
Example 4
Source File: ObdDataPlotter.java    From AndrOBD with GNU General Public License v3.0 5 votes vote down vote up
/**
 * add a new series to the graph
 *
 * @param series The new series to be added
 */
public synchronized void addSeries(TimeSeries series)
{

	if (oneRangePerSeries)
	{
		// get paint for current axis/range/...
		Paint currPaint =
			DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[
				raIndex % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length];

		XYPlot plot = (XYPlot) chart.getPlot();
		// set dataset
		plot.setDataset(raIndex, new TimeSeriesCollection(series));
		// ** set axis
		NumberAxis axis = new NumberAxis();
		axis.setTickLabelFont(legendFont);
		axis.setAxisLinePaint(currPaint);
		axis.setTickLabelPaint(currPaint);
		axis.setTickMarkPaint(currPaint);
		// ** set axis in plot
		plot.setRangeAxis(raIndex, axis);
		plot.setRangeAxisLocation(raIndex, raIndex % 2 == 0 ? AxisLocation.TOP_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT);
		plot.mapDatasetToRangeAxis(raIndex, raIndex);
		// ** create renderer
		XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
		renderer.setBaseToolTipGenerator(toolTipGen);
		renderer.setSeriesPaint(0, currPaint);
		// ** set renderer in plot
		plot.setRenderer(raIndex, renderer);

		raIndex++;
	}
	dataset.addSeries(series);
}
 
Example 5
Source File: IsotopePeakScannerSetupDialog.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private void formatChart() {
  theme.apply(chart);
  plot = chart.getXYPlot();
  plot.addRangeMarker(new ValueMarker(minIntensity, belowMin, new BasicStroke(1.0f)));
  ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride(mzFormat);
  ((NumberAxis) plot.getRangeAxis()).setNumberFormatOverride(intFormat);

  XYItemRenderer r = plot.getRenderer();
  r.setSeriesPaint(0, aboveMin);
  r.setSeriesPaint(1, belowMin);
  r.setDefaultToolTipGenerator(ttGen);
}
 
Example 6
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * A test for a bug where setting the renderer doesn't register the plot
 * as a RendererChangeListener.
 */
@Test
public void testSetRenderer() {
    XYPlot plot = new XYPlot();
    XYItemRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    // now make a change to the renderer and see if it triggers a plot
    // change event...
    MyPlotChangeListener listener = new MyPlotChangeListener();
    plot.addChangeListener(listener);
    renderer.setSeriesPaint(0, Color.black);
    assertTrue(listener.getEvent() != null);
}
 
Example 7
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for a bug where setting the renderer doesn't register the plot
 * as a RendererChangeListener.
 */
@Test
public void testSetRenderer() {
    XYPlot plot = new XYPlot();
    XYItemRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    // now make a change to the renderer and see if it triggers a plot
    // change event...
    MyPlotChangeListener listener = new MyPlotChangeListener();
    plot.addChangeListener(listener);
    renderer.setSeriesPaint(0, Color.black);
    assertTrue(listener.getEvent() != null);
}
 
Example 8
Source File: XYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for a bug where setting the renderer doesn't register the plot
 * as a RendererChangeListener.
 */
public void testSetRenderer() {
    XYPlot plot = new XYPlot();
    XYItemRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    // now make a change to the renderer and see if it triggers a plot
    // change event...
    MyPlotChangeListener listener = new MyPlotChangeListener();
    plot.addChangeListener(listener);
    renderer.setSeriesPaint(0, Color.black);
    assertTrue(listener.getEvent() != null);
}
 
Example 9
Source File: PlotterModel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
public void setColorRGB(int series, float r, float g, float b){
    Plot currentPlot = availablePlots.get(currentPlotIndex);
    XYPlot dPlot = currentPlot.getChartPanel().getChart().getXYPlot();
    XYItemRenderer renderer = dPlot.getRenderer();
    renderer.setSeriesPaint(series, new Color(r, g, b));
    //renderer.setBaseStroke(new BasicStroke(3.0f));
}
 
Example 10
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A test for a bug where setting the renderer doesn't register the plot
 * as a RendererChangeListener.
 */
@Test
public void testSetRenderer() {
    XYPlot plot = new XYPlot();
    XYItemRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);
    // now make a change to the renderer and see if it triggers a plot
    // change event...
    MyPlotChangeListener listener = new MyPlotChangeListener();
    plot.addChangeListener(listener);
    renderer.setSeriesPaint(0, Color.black);
    assertTrue(listener.getEvent() != null);
}
 
Example 11
Source File: SpectrumTopComponent.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void updateRenderer(int seriesIndex, Color seriesColor, DisplayableSpectrum spectrum, JFreeChart chart) {
    final XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    renderer.setSeriesPaint(seriesIndex, seriesColor);
    final Stroke lineStyle = spectrum.getLineStyle();
    renderer.setSeriesStroke(seriesIndex, lineStyle);
    Shape symbol = spectrum.getScaledShape();
    renderer.setSeriesShape(seriesIndex, symbol);
}
 
Example 12
Source File: SimpleScatter.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public JFreeChart createChart(DatasetMap datasets) {

		DefaultXYDataset dataset=(DefaultXYDataset)datasets.getDatasets().get("1");

		JFreeChart chart = ChartFactory.createScatterPlot(
				name, yLabel, xLabel, dataset, 
				PlotOrientation.HORIZONTAL, false, true, false);

		Font font = new Font("Tahoma", Font.BOLD, titleDimension);
		//TextTitle title = new TextTitle(name, font);
		TextTitle title =setStyleTitle(name, styleTitle);
		chart.setTitle(title);
		chart.setBackgroundPaint(Color.white);
		if(subName!= null && !subName.equals("")){
			TextTitle subTitle =setStyleTitle(subName, styleSubTitle);
			chart.addSubtitle(subTitle);
		}
		
		XYPlot plot = (XYPlot) chart.getPlot();
		plot.setForegroundAlpha(0.65f);

		XYItemRenderer renderer = plot.getRenderer();


		int seriesN=dataset.getSeriesCount();
		if(colorMap!=null){
			for (int i = 0; i < seriesN; i++) {
				String serieName=(String)dataset.getSeriesKey(i);
				Color color=(Color)colorMap.get(serieName);
				if(color!=null){
					renderer.setSeriesPaint(i, color);
				}	
			}
		}

		// increase the margins to account for the fact that the auto-range 
		// doesn't take into account the bubble size...
		NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
		domainAxis.setAutoRange(true);
		domainAxis.setRange(yMin, yMax);
		NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
		rangeAxis.setAutoRange(true);
		rangeAxis.setRange(xMin,xMax);
		
		if(legend==true){
			drawLegend(chart);
		}
		return chart;
	}
 
Example 13
Source File: SWTMultipleAxisDemo1.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @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;
}
 
Example 14
Source File: SWTMultipleAxisDemo1.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @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;
}
 
Example 15
Source File: SimpleChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void handleXYPlotSettings(XYPlot p, JRChartPlot jrPlot)
	{
		PlotSettings plotSettings = getPlotSettings();
		XYItemRenderer xyItemRenderer = p.getRenderer();
		Paint[] paintSequence = getPaintSequence(plotSettings, jrPlot);	
		if (paintSequence != null)
		{
			for (int i = 0; i < paintSequence.length; i++)
			{
				xyItemRenderer.setSeriesPaint(i, paintSequence[i]);
			}
		}
		Paint[] outlinePaintSequence = getOutlinePaintSequence(plotSettings);	
		if (outlinePaintSequence != null)
		{
			for (int i = 0; i < outlinePaintSequence.length; i++)
			{
				xyItemRenderer.setSeriesOutlinePaint(i, outlinePaintSequence[i]);
			}
		}
		Stroke[] strokeSequence = getStrokeSequence(plotSettings);
		if (strokeSequence != null)
		{
			for (int i = 0; i < strokeSequence.length; i++)
			{
				xyItemRenderer.setSeriesStroke(i, strokeSequence[i]);
			}
		}
		Stroke[] outlineStrokeSequence = getOutlineStrokeSequence(plotSettings);
		if (outlineStrokeSequence != null)
		{
			for (int i = 0; i < outlineStrokeSequence.length; i++)
			{
				xyItemRenderer.setSeriesOutlineStroke(i, outlineStrokeSequence[i]);
			}
		}
		
		Boolean domainGridlineVisible = plotSettings.getDomainGridlineVisible();
		if (domainGridlineVisible == null || domainGridlineVisible)
		{
			PaintProvider domainGridlinePaint = plotSettings.getDomainGridlinePaint();
			if (domainGridlinePaint != null)
			{
				p.setDomainGridlinePaint(domainGridlinePaint.getPaint());
			}
			Stroke domainGridlineStroke = plotSettings.getDomainGridlineStroke();
			if (domainGridlineStroke != null)
			{
				p.setDomainGridlineStroke(domainGridlineStroke);
			}
			
		}
		Boolean rangeGridlineVisible = plotSettings.getRangeGridlineVisible();
		if (rangeGridlineVisible == null || rangeGridlineVisible)
		{
			PaintProvider rangeGridlinePaint = plotSettings.getRangeGridlinePaint();
			if (rangeGridlinePaint != null)
			{
				p.setRangeGridlinePaint(rangeGridlinePaint.getPaint());
			}
			Stroke rangeGridlineStroke = plotSettings.getRangeGridlineStroke();
			if (rangeGridlineStroke != null)
			{
				p.setRangeGridlineStroke(rangeGridlineStroke);
			}
		}
		
//		p.setRangeZeroBaselineVisible(true);
		
	}
 
Example 16
Source File: SWTMultipleAxisDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @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));
    plot.getRangeAxis().setFixedDimension(15.0);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);

    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setFixedDimension(10.0);
    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;
}
 
Example 17
Source File: SWTMultipleAxisDemo1.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 *
 * @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;
}
 
Example 18
Source File: SWTMultipleAxisDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the demo chart.
 * 
 * @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));
    plot.getRangeAxis().setFixedDimension(15.0);
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);
   
    // AXIS 2
    NumberAxis axis2 = new NumberAxis("Range Axis 2");
    axis2.setFixedDimension(10.0);
    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;
}
 
Example 19
Source File: CombinedXYPlotDemo1.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates an overlaid chart.
 *
 * @return The chart.
 */
private static JFreeChart createCombinedChart() {

    // create plot ...
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    renderer1.setSeriesStroke(0, new BasicStroke(4.0f,
            BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);

    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.02);
    ValueAxis rangeAxis = new NumberAxis("$billion");
    XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // add a second dataset and renderer...
    IntervalXYDataset data2 = createDataset2();
    XYBarRenderer renderer2 = new XYBarRenderer() {
        public Paint getItemPaint(int series, int item) {
            XYDataset dataset = getPlot().getDataset();
            if (dataset.getYValue(series, item) >= 0.0) {
                return Color.red;
            }
            else {
                return Color.green;
            }
        }
    };
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setDrawBarOutline(false);
    renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));

    XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"),
            renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1",
            JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    chart.setBackgroundPaint(Color.white);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);
    return chart;
}
 
Example 20
Source File: CombinedXYPlotDemo1.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates an overlaid chart.
 *
 * @return The chart.
 */
private static JFreeChart createCombinedChart() {

    // create plot ...
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    renderer1.setSeriesStroke(0, new BasicStroke(4.0f,
            BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);

    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.02);
    ValueAxis rangeAxis = new NumberAxis("$billion");
    XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);

    // add a second dataset and renderer...
    IntervalXYDataset data2 = createDataset2();
    XYBarRenderer renderer2 = new XYBarRenderer() {
        public Paint getItemPaint(int series, int item) {
            XYDataset dataset = getPlot().getDataset();
            if (dataset.getYValue(series, item) >= 0.0) {
                return Color.red;
            }
            else {
                return Color.green;
            }
        }
    };
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setDrawBarOutline(false);
    renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
            new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));

    XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"),
            renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);

    CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);

    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1",
            JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    chart.setBackgroundPaint(Color.white);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);
    return chart;
}