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

The following examples show how to use org.jfree.chart.plot.XYPlot#setRangeGridlinePaint() . 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: StatisticsView.java    From Creatures with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createChart(final XYDataset dataset, Vector<Color> colors) {
	final JFreeChart chart = ChartFactory.createXYLineChart(
			"Creature Statistics",
			"Time",
			"Value",
			dataset,
			PlotOrientation.VERTICAL,
			true,
			true,
			false
			);

	chart.setBackgroundPaint(Color.white);

	final XYPlot plot = chart.getXYPlot();
	for (int k = 0; k < colors.size(); k++) {
		plot.getRenderer().setSeriesPaint(k, colors.elementAt(k));
	}
	
	plot.setBackgroundPaint(Color.lightGray);
	plot.setDomainGridlinePaint(Color.white);
	plot.setRangeGridlinePaint(Color.white);

	return chart;
}
 
Example 2
Source File: HistogramChartFactory.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 3
Source File: HistogramChartFactory.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 4
Source File: ChartUtils.java    From PDV with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set XY color
 * @param plot XY plot
 */
private static void setYAixs(XYPlot plot) {
    Color lineColor = new Color(192, 208, 224);
    ValueAxis axis = plot.getRangeAxis();
    axis.setAxisLinePaint(lineColor);
    axis.setTickMarkPaint(lineColor);

    axis.setAutoRange(true);
    axis.setAxisLineVisible(false);
    axis.setTickMarksVisible(false);
    plot.setRangeGridlinePaint(new Color(192, 192, 192));
    plot.setRangeGridlineStroke(new BasicStroke(1));

    plot.getRangeAxis().setUpperMargin(0.1);
    plot.getRangeAxis().setLowerMargin(0.1);
}
 
Example 5
Source File: TimeSeriesChartDemo1.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
            "Legal & General Unit Trust Prices", "Date", "Price Per Unit",
            dataset, true);

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}
 
Example 6
Source File: SWTTimeSeriesDemo.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);
    
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    return chart;

}
 
Example 7
Source File: TimeSeriesChartDemo1.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}
 
Example 8
Source File: SWTTimeSeriesDemo.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);
    
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    return chart;

}
 
Example 9
Source File: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createScatterChart() throws JRException
{
	JFreeChart jfreeChart = super.createScatterChart();
	XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
	
	xyPlot.setRangeGridlinePaint(SCATTER_GRIDLINE_COLOR);
	xyPlot.setRangeGridlineStroke(new BasicStroke(0.75f));
	xyPlot.setDomainGridlinesVisible(true);
	xyPlot.setDomainGridlinePaint(SCATTER_GRIDLINE_COLOR);
	xyPlot.setDomainGridlineStroke(new BasicStroke(0.75f));
	xyPlot.setRangeZeroBaselinePaint(ChartThemesConstants.GRAY_PAINT_134);

	XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer)xyPlot.getRenderer();
	lineRenderer.setUseFillPaint(true);
	JRScatterPlot scatterPlot = (JRScatterPlot) getPlot();
	boolean isShowLines = scatterPlot.getShowLines() == null ? false : scatterPlot.getShowLines();
	lineRenderer.setBaseLinesVisible(isShowLines);
	XYDataset xyDataset = xyPlot.getDataset();
	if (xyDataset != null)
	{
		for (int i = 0; i < xyDataset.getSeriesCount(); i++)
		{
			lineRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			lineRenderer.setSeriesFillPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
			lineRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(i));
			//lineRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6));
		}
	}
	return jfreeChart;
}
 
Example 10
Source File: CandlestickChart.java    From ta4j-origins with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    /**
     * Getting time series
     */
    TimeSeries series = CsvTradesLoader.loadBitstampSeries();
    
    /**
     * Creating the OHLC dataset
     */
    OHLCDataset ohlcDataset = createOHLCDataset(series);
    
    /**
     * Creating the additional dataset
     */
    TimeSeriesCollection xyDataset = createAdditionalDataset(series);
    
    /**
     * Creating the chart
     */
    JFreeChart chart = ChartFactory.createCandlestickChart(
            "Bitstamp BTC price",
            "Time",
            "USD",
            ohlcDataset,
            true);
    // Candlestick rendering
    CandlestickRenderer renderer = new CandlestickRenderer();
    renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST);
    XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    // Additional dataset
    int index = 1;
    plot.setDataset(index, xyDataset);
    plot.mapDatasetToRangeAxis(index, 0);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
    renderer2.setSeriesPaint(index, Color.blue);
    plot.setRenderer(index, renderer2);
    // Misc
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setBackgroundPaint(Color.white);
    NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
    numberAxis.setAutoRangeIncludesZero(false);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    
    /**
     * Displaying the chart
     */
    displayChart(chart);
}
 
Example 11
Source File: DeviationChartPlotter.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private JFreeChart createChart(XYDataset dataset, boolean createLegend) {

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

		chart.setBackgroundPaint(Color.white);

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

		DeviationRenderer renderer = new DeviationRenderer(true, false);
		Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
		if (dataset.getSeriesCount() == 1) {
			renderer.setSeriesStroke(0, stroke);
			renderer.setSeriesPaint(0, Color.RED);
			renderer.setSeriesFillPaint(0, Color.RED);
		} else {
			for (int i = 0; i < dataset.getSeriesCount(); i++) {
				renderer.setSeriesStroke(i, stroke);
				Color color = getColorProvider().getPointColor((double) i / (double) (dataset.getSeriesCount() - 1));
				renderer.setSeriesPaint(i, color);
				renderer.setSeriesFillPaint(i, color);
			}
		}
		renderer.setAlpha(0.12f);

		plot.setRenderer(renderer);

		ValueAxis valueAxis = plot.getRangeAxis();
		valueAxis.setLabelFont(LABEL_FONT_BOLD);
		valueAxis.setTickLabelFont(LABEL_FONT);

		return chart;
	}
 
Example 12
Source File: TimeSeriesChartDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);
    
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    return chart;

}
 
Example 13
Source File: DiagramRenderer.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
protected JFreeChart renderPreChart(Map<String, OXFFeatureCollection> entireCollMap, String[] observedProperties,
        ArrayList<TimeSeriesCollection> timeSeries, Calendar begin, Calendar end) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(null, // title
            "Date", // x-axis label
            observedProperties[0], // y-axis label
            timeSeries.get(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.setRange(begin.getTime(), end.getTime());
    axis.setDateFormatOverride(new SimpleDateFormat());
    axis.setTimeZone(end.getTimeZone());
    for (int i = 1; i < observedProperties.length; i++) {
        XYDataset additionalDataset = timeSeries.get(i);
        plot.setDataset(i, additionalDataset);
        plot.setRangeAxis(i, new NumberAxis(observedProperties[i]));
        // plot.getRangeAxis(i).setRange((Double)
        // overAllSeriesCollection.getMinimum(i),
        // (Double) overAllSeriesCollection.getMaximum(i));
        plot.mapDatasetToRangeAxis(i, i);
        // plot.getDataset().getXValue(i, i);
    }
    return chart;
}
 
Example 14
Source File: WinrateHistogramDialog.java    From mylizzie with GNU General Public License v3.0 4 votes vote down vote up
private void initCustomComponents() {
    WinrateHistogramTableModel winrateHistogramTableModel = new WinrateHistogramTableModel(tableWinrateHistory);
    tableWinrateHistory.setModel(winrateHistogramTableModel);

    XYSeries blackSeries = new XYSeries("Black");
    XYSeries whiteSeries = new XYSeries("White");
    XYSeries standardSeries = new XYSeries("50%");
    for (int i = 0; i <= 50; ++i) {
        standardSeries.add(i, 50);
    }

    dataSet = new XYSeriesCollection();
    dataSet.addSeries(blackSeries);
    dataSet.addSeries(whiteSeries);
    dataSet.addSeries(standardSeries);

    JFreeChart chart = ChartFactory.createXYLineChart(
            "", // chart title
            "", // x axis label
            "Win%", // y axis label
            dataSet, // data
            PlotOrientation.VERTICAL,
            true, // include legend
            true, // tooltips
            false // urls
    );

    chart.setBackgroundPaint(Color.WHITE);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setRange(0.0, 100.0);

    histogramChartPanel = new ChartPanel(chart);
    panelWinrateHistogram.add(histogramChartPanel);

    winrateHistogramTableModel.setRefreshObserver(new Consumer<WinrateHistogramTableModel>() {
        private long lastRefreshTime = System.currentTimeMillis();

        @Override
        public void accept(WinrateHistogramTableModel model) {
            long currentTime = System.currentTimeMillis();
            if (currentTime - lastRefreshTime < 250L) {
                return;
            }

            lastRefreshTime = currentTime;

            SwingUtilities.invokeLater(() -> {
                blackSeries.clear();
                whiteSeries.clear();
                standardSeries.clear();

                for (int i = 0; i < model.getHistogramEntryList().size(); ++i) {
                    WinrateHistogramEntry entry = model.getHistogramEntryList().get(i);

                    standardSeries.add(entry.getMoveNumber(), 50);
                    if (checkBoxHistogramShowBlack.isSelected()) {
                        blackSeries.add(entry.getMoveNumber(), entry.getBlackWinrate());
                    }
                    if (checkBoxHistogramShowWhite.isSelected()) {
                        whiteSeries.add(entry.getMoveNumber(), entry.getWhiteWinrate());
                    }
                }
                if (model.getHistogramEntryList().size() < 50) {
                    for (int i = model.getHistogramEntryList().size() - 1; i <= 50; ++i) {
                        standardSeries.add(i, 50);
                    }
                }

                histogramChartPanel.repaint();
            });
        }
    });

    setPreferredSize(new Dimension(
            Lizzie.optionSetting.getWinrateHistogramWindowState().getWidth()
            , Lizzie.optionSetting.getWinrateHistogramWindowState().getHeight()
    ));
    splitPaneHistogram.setDividerLocation(0.3);
    pack();

    histogramChartPanel.setPreferredSize(new Dimension(panelWinrateHistogram.getWidth(), panelWinrateHistogram.getHeight()));
    histogramChartPanel.setSize(panelWinrateHistogram.getWidth(), panelWinrateHistogram.getHeight());
    pack();
}
 
Example 15
Source File: SWTTimeSeriesDemo.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a chart.
 *
 * @param dataset  a dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        true,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);
    //plot.setForegroundAlpha(0.5f);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }

    // code to test the alpha channel
    IntervalMarker interv = new IntervalMarker(120, 150,
            Color.blue, new BasicStroke(5.0f),null,null,0.2f);
    plot.addRangeMarker(interv);

    // code to test the alpha channel within awt colors
    XYDifferenceRenderer differenceRenderer= new XYDifferenceRenderer(
            new Color(255, 0, 0, 128),new Color(0, 255, 0, 128), false);
    plot.setRenderer(differenceRenderer);

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    return chart;

}
 
Example 16
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 17
Source File: FrmElevationFilter.java    From Course_Generator with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update the chart
 * 
 * @param dataset1
 * @param dataset2
 * @return
 */
private JFreeChart CreateChart(XYDataset dataset1, XYDataset dataset2) {
	JFreeChart chart = ChartFactory.createXYAreaChart("",
			// x axis label
			bundle.getString("frmElevationFilter.labelX"), // "Distance"
			// y axis label
			bundle.getString("frmElevationFilter.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);
	renderer2.setSeriesStroke(0, new BasicStroke(1.0f));
	plot.setRenderer(1, renderer2);

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

	return chart;
}
 
Example 18
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 19
Source File: XYTitleAnnotationDemo1.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createTimeSeriesChart(
        "Legal & General Unit Trust Prices",  // title
        "Date",             // x-axis label
        "Price Per Unit",   // y-axis label
        dataset,            // data
        false,               // create legend?
        true,               // generate tooltips?
        false               // generate URLs?
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = (XYPlot) chart.getPlot();
    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.setRangeCrosshairVisible(true);

    LegendTitle lt = new LegendTitle(plot);
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 9));
    lt.setBackgroundPaint(new Color(200, 200, 255, 100));
    lt.setFrame(new BlockBorder(Color.white));
    lt.setPosition(RectangleEdge.BOTTOM);
    XYTitleAnnotation ta = new XYTitleAnnotation(0.98, 0.02, lt, 
            RectangleAnchor.BOTTOM_RIGHT);
    
    ta.setMaxWidth(0.48);
    plot.addAnnotation(ta);

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
    }
    
    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    
    ValueAxis yAxis = plot.getRangeAxis();
    yAxis.setLowerMargin(0.35);
    return chart;

}
 
Example 20
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);
		
	}