Java Code Examples for org.jfree.chart.plot.XYPlot#setRenderer()

The following examples show how to use org.jfree.chart.plot.XYPlot#setRenderer() . 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: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
                                                String timeAxisLabel,
                                                String valueAxisLabel,
                                                OHLCDataset dataset,
                                                boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    return chart;

}
 
Example 2
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 6 votes vote down vote up
public JFreeChart scatterGridPlot(String xLabel, String yLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xLabel
            , yLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example 3
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 6 votes vote down vote up
/**
 * Performing scatter plot with grid
 * @param xLabel
 * @param yLabel
 */
public JFreeChart scatterGridPlot(String xLabel, String yLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xLabel
            , yLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example 4
Source File: ChartFactory.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code> 
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code> 
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
                                                String timeAxisLabel,
                                                String valueAxisLabel,
                                                OHLCDataset dataset,
                                                boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    return chart;

}
 
Example 5
Source File: StackedXYAreaRenderer2Test.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));

    // try null argument
    assertNull(renderer.findRangeBounds(null));

    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
 
Example 6
Source File: JPanelProfil.java    From Course_Generator with GNU General Public License v3.0 6 votes vote down vote up
private JFreeChart CreateChartProfil(XYDataset dataset) {
	JFreeChart chart = ChartFactory.createXYAreaChart("", "Distance", // x axis label
			"Elevation", // y axis label
			dataset, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	chart.setBackgroundPaint(Color.white); // Panel background color
	XYPlot plot = chart.getXYPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(renderer);

	// NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
	// rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

	return chart;
}
 
Example 7
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 6 votes vote down vote up
public JFreeChart scatterGridPlot(String xLabel, String yLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xLabel
            , yLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example 8
Source File: StackedXYBarRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("Test Chart",
            "X", "Y", dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));
}
 
Example 9
Source File: ChartJFreeChartOutputHeatmap.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void createNewSerie(final IScope scope, final String serieid) {

	final ChartDataSeries dataserie = chartdataset.getDataSeries(scope, serieid);
	final MatrixSeries serie = new MatrixSeries((String) dataserie.getSerieLegend(scope),
			Math.max(1, this.getChartdataset().getYSeriesValues().size()),
			Math.max(1, this.getChartdataset().getXSeriesValues().size()));
	final XYPlot plot = (XYPlot) this.chart.getPlot();

	final MatrixSeriesCollection firstdataset = (MatrixSeriesCollection) plot.getDataset();

	if (!IdPosition.containsKey(serieid)) {

		if (firstdataset.getSeriesCount() == 0) {
			firstdataset.addSeries(serie);
			plot.setDataset(0, firstdataset);

		} else {

			final MatrixSeriesCollection newdataset = new MatrixSeriesCollection();
			newdataset.addSeries(serie);
			jfreedataset.add(newdataset);
			plot.setDataset(jfreedataset.size() - 1, newdataset);

		}
		plot.setRenderer(jfreedataset.size() - 1, (XYItemRenderer) getOrCreateRenderer(scope, serieid));
		IdPosition.put(serieid, jfreedataset.size() - 1);
		// DEBUG.LOG("new serie"+serieid+" at
		// "+IdPosition.get(serieid)+" fdsize "+plot.getSeriesCount()+" jfds
		// "+jfreedataset.size()+" datasc "+plot.getDatasetCount());
		// TODO Auto-generated method stub

	}
}
 
Example 10
Source File: GenericChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected JFreeChart createBubbleChart() throws JRException 
{
	ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
	JFreeChart jfreeChart = 
		ChartFactory.createBubbleChart(
			evaluateTextExpression(getChart().getTitleExpression()),
			evaluateTextExpression(((JRBubblePlot)getPlot()).getXAxisLabelExpression()),
			evaluateTextExpression(((JRBubblePlot)getPlot()).getYAxisLabelExpression()),
			 (XYZDataset)getDataset(),
			 getPlot().getOrientationValue().getOrientation(),
			 isShowLegend(),
			 true,
			 false);

	configureChart(jfreeChart, getPlot());

	XYPlot xyPlot = (XYPlot)jfreeChart.getPlot();
	JRBubblePlot bubblePlot = (JRBubblePlot)getPlot();
	int scaleType = bubblePlot.getScaleTypeValue() == null ? ScaleTypeEnum.ON_RANGE_AXIS.getValue() : bubblePlot.getScaleTypeValue().getValue();
	XYBubbleRenderer bubbleRenderer = new XYBubbleRenderer( scaleType );
	xyPlot.setRenderer( bubbleRenderer );

	// Handle the axis formating for the category axis
	configureAxis(xyPlot.getDomainAxis(), bubblePlot.getXAxisLabelFont(),
			bubblePlot.getXAxisLabelColor(), bubblePlot.getXAxisTickLabelFont(),
			bubblePlot.getXAxisTickLabelColor(), bubblePlot.getXAxisTickLabelMask(), bubblePlot.getXAxisVerticalTickLabels(),
			bubblePlot.getOwnXAxisLineColor(), false,
			(Comparable<?>)evaluateExpression(bubblePlot.getDomainAxisMinValueExpression()), 
			(Comparable<?>)evaluateExpression(bubblePlot.getDomainAxisMaxValueExpression()));

	// Handle the axis formating for the value axis
	configureAxis(xyPlot.getRangeAxis(), bubblePlot.getYAxisLabelFont(),
			bubblePlot.getYAxisLabelColor(), bubblePlot.getYAxisTickLabelFont(),
			bubblePlot.getYAxisTickLabelColor(), bubblePlot.getYAxisTickLabelMask(), bubblePlot.getYAxisVerticalTickLabels(),
			bubblePlot.getOwnYAxisLineColor(), true,
			(Comparable<?>)evaluateExpression(bubblePlot.getRangeAxisMinValueExpression()), 
			(Comparable<?>)evaluateExpression(bubblePlot.getRangeAxisMaxValueExpression()));

	return jfreeChart;
}
 
Example 11
Source File: ChartFactory.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns a default instance of a candlesticks chart.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param timeAxisLabel  a label for the time axis (<code>null</code>
 *                       permitted).
 * @param valueAxisLabel  a label for the value axis (<code>null</code>
 *                        permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 *
 * @return A candlestick chart.
 */
public static JFreeChart createCandlestickChart(String title,
        String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset,
        boolean legend) {

    ValueAxis timeAxis = new DateAxis(timeAxisLabel);
    NumberAxis valueAxis = new NumberAxis(valueAxisLabel);
    XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null);
    plot.setRenderer(new CandlestickRenderer());
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example 12
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 5 votes vote down vote up
/**
 * Performing scatter plot
 * @param xAxisLabel
 * @param yAxisLabel
 */
public JFreeChart scatterPlot(String xAxisLabel,String yAxisLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xAxisLabel
            , yAxisLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    switch(seriesTypes.get(0)){
            case DOTS:
                plot.setRenderer(0, new XYLineAndShapeRenderer(false, true));
                break;
            case LINES:
                plot.setRenderer(0, new XYLineAndShapeRenderer(true, true));
                break;
        }
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        switch(seriesTypes.get(i)){
            case DOTS:
                plot.setRenderer(i, new XYLineAndShapeRenderer(false, true));
                break;
            case LINES:
                plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
                break;
        }
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example 13
Source File: StackedXYBarRendererTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));
}
 
Example 14
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 5 votes vote down vote up
public JFreeChart scatterPlot(String xAxisLabel,String yAxisLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xAxisLabel
            , yAxisLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    switch(seriesTypes.get(0)){
            case DOTS:
                plot.setRenderer(0, new XYLineAndShapeRenderer(false, true));
                break;
            case LINES:
                plot.setRenderer(0, new XYLineAndShapeRenderer(true, true));
                break;
        }
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        switch(seriesTypes.get(i)){
            case DOTS:
                plot.setRenderer(i, new XYLineAndShapeRenderer(false, true));
                break;
            case LINES:
                plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
                break;
        }
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example 15
Source File: KendrickMassPlotTask.java    From mzmine2 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * create 2D Kendrick mass plot
 */
private JFreeChart create2DKendrickMassPlot() {

  if (zAxisLabel.equals("none")) {
    logger.info("Creating new 2D chart instance");
    appliedSteps++;

    // load dataset
    dataset2D = new KendrickMassPlotXYDataset(parameterSet);

    // create chart
    chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, dataset2D,
        PlotOrientation.VERTICAL, true, true, true);

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainCrosshairPaint(Color.GRAY);
    plot.setRangeCrosshairPaint(Color.GRAY);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    appliedSteps++;

    // set axis
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(0, 1);
    if (xAxisLabel.contains("KMD")) {
      domain.setRange(0, 1);
    }

    // set renderer
    XYBlockPixelSizeRenderer renderer = new XYBlockPixelSizeRenderer();

    // set tooltip generator
    ScatterPlotToolTipGenerator tooltipGenerator =
        new ScatterPlotToolTipGenerator(xAxisLabel, yAxisLabel, zAxisLabel, rows);
    renderer.setSeriesToolTipGenerator(0, tooltipGenerator);
    plot.setRenderer(renderer);

    // set item label generator
    NameItemLabelGenerator generator = new NameItemLabelGenerator(rows);
    renderer.setDefaultItemLabelGenerator(generator);
    renderer.setDefaultItemLabelsVisible(false);
    renderer.setDefaultItemLabelFont(legendFont);
    renderer.setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER,
        TextAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -45), true);
  }
  return chart;
}
 
Example 16
Source File: SparkLine.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
private void addMarker(int index, double value, final Color color,  float stoke, XYPlot plot) {
	logger.debug("IN");
	TimeSeries markerSeries = new TimeSeries("Marker" + index, Month.class);
	for (Iterator iterator = yearsDefined.iterator(); iterator.hasNext();) {
		String currentYear = (String) iterator.next();
		boolean stop=false;			
		for(int i = 1; i < 13 && stop==false; i++) {
			if(!(currentYear.equalsIgnoreCase(yearsDefined.first()) && i<firstMonth.getMonth())){
				markerSeries.add(new Month(i, Integer.valueOf(currentYear).intValue()), value);
			}
			if(currentYear.equalsIgnoreCase(lastYear) && i>=lastMonth.getMonth()){
				stop=true;
			}
		}
	}

	final TimeSeriesCollection dataset = new TimeSeriesCollection(markerSeries); 


	XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { 
		public boolean getItemShapeVisible(int _series, int item) { 
			return (false); 
		} 

		public Paint getItemPaint(int row, int column) {
			return color;
		}
	}; 

	renderer.setBaseStroke(new BasicStroke(stoke, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));

	renderer.setBaseShapesVisible(true); 
	renderer.setBaseShapesFilled(true); 
	renderer.setDrawOutlines(true); 
	renderer.setUseFillPaint(true); 
	renderer.setBaseFillPaint(Color.GRAY); 
	renderer.setBaseOutlinePaint(Color.BLACK); 
	renderer.setUseOutlinePaint(true); 

	plot.setDataset(index, dataset);
	plot.setRenderer(index, renderer);		
	logger.debug("OUT");
}
 
Example 17
Source File: MsSpectrumPlotWindowController.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
private void configureRenderer(MsSpectrumDataSet dataset, int datasetIndex) {

    final MsSpectrumType renderingType = dataset.getRenderingType();
    final XYPlot plot = chartNode.getChart().getXYPlot();

    // Set renderer
    AbstractXYItemRenderer newRenderer;
    switch (renderingType) {
      case PROFILE:
      case THRESHOLDED:
        XYLineAndShapeRenderer newLineRenderer = new XYLineAndShapeRenderer();
        final int lineThickness = dataset.getLineThickness();
        newLineRenderer.setBaseShape(new Ellipse2D.Double(-2 * lineThickness, -2 * lineThickness,
            4 * lineThickness + 1, 4 * lineThickness + 1));
        newLineRenderer.setBaseShapesFilled(true);
        newLineRenderer.setBaseShapesVisible(dataset.getShowDataPoints());
        newLineRenderer.setDrawOutlines(false);

        Stroke baseStroke = new BasicStroke(lineThickness);
        newLineRenderer.setBaseStroke(baseStroke);
        newRenderer = newLineRenderer;
        break;
      case CENTROIDED:
      default:
        XYBarRenderer newBarRenderer = new XYBarRenderer();
        // Avoid gradients
        newBarRenderer.setBarPainter(new StandardXYBarPainter());
        newBarRenderer.setShadowVisible(false);
        newRenderer = newBarRenderer;
        break;
    }

    // Set tooltips for legend
    newRenderer.setLegendItemToolTipGenerator((ds, series) -> {
      if (ds instanceof MsSpectrumDataSet) {
        return ((MsSpectrumDataSet) ds).getDescription();
      } else
        return null;
    });

    // Set color
    Color baseColor = dataset.getColor();
    newRenderer.setBasePaint(JavaFXUtil.convertColorToAWT(baseColor));

    // Set label generator
    XYItemLabelGenerator intelligentLabelGenerator =
        new IntelligentItemLabelGenerator(chartNode, 100, dataset);
    newRenderer.setBaseItemLabelGenerator(intelligentLabelGenerator);
    newRenderer.setBaseItemLabelPaint(JavaFXUtil.convertColorToAWT(labelsColor));
    newRenderer.setBaseItemLabelsVisible(itemLabelsVisible.get());

    // Set tooltip generator
    newRenderer.setBaseToolTipGenerator(dataset);

    plot.setRenderer(datasetIndex, newRenderer);

  }
 
Example 18
Source File: JPanelAnalysisTimeDist.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYAreaChart("",
			// x axis label
			bundle.getString("JPanelAnalysisTimeDist.labelX"), // "Distance"
			// y axis label
			bundle.getString("JPanelAnalysisTimeDist.labelY1"), // "Elevation"
			dataset1, // data
			PlotOrientation.VERTICAL, false, // include legend
			true, // tooltips
			false // urls
	);

	// -- Background color
	chart.setBackgroundPaint(Color.white);
	chart.setAntiAlias(true);

	XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.white);
	plot.setDomainGridlinePaint(Color.gray);
	plot.setRangeGridlinePaint(Color.gray);
	plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

	XYAreaRenderer renderer = new XYAreaRenderer();
	renderer.setSeriesPaint(0, new Color(0x99, 0xff, 0x00));
	renderer.setOutline(true);
	renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
	plot.setRenderer(0, renderer);

	NumberAxis rangeAxis2 = new NumberAxis(bundle.getString("JPanelAnalysisTimeDist.labelY2")); // "Time"
	plot.setRangeAxis(1, rangeAxis2);
	plot.setDataset(1, dataset2);
	plot.setRangeAxis(1, rangeAxis2);
	plot.mapDatasetToRangeAxis(1, 1);
	StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
	renderer2.setSeriesPaint(0, Color.red);
	plot.setRenderer(1, renderer2);

	// -- Select the display order
	plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

	return chart;
}
 
Example 19
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 20
Source File: GraphPlot.java    From NSGA-II with MIT License 3 votes vote down vote up
public void configureMultiplePlotter(final String x_axis, final String y_axis, final String graphTitle) {
    
    JFreeChart xyLineChart = ChartFactory.createXYLineChart(graphTitle, x_axis, y_axis, MULTIPLE_DATASET, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartPanel = new ChartPanel(xyLineChart);
    
    chartPanel.setPreferredSize(new java.awt.Dimension(DIMENSION_X, DIMENSION_Y));
    
    final XYPlot plot = xyLineChart.getXYPlot();
    
    plot.setRenderer(MULTIPLE_RENDERER);
    setContentPane(chartPanel);
}