List of usage examples for org.jfree.chart.plot XYPlot setRenderer
public void setRenderer(int index, XYItemRenderer renderer)
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Modify a scatter plot to show linear regression or not. * @param scatterPlot Scatter plot to modify * @param enabled Indicates if linear regression has to be shown *//* w w w . ja v a2s .c o m*/ public static void setScatterPlotLinearRegressionEnabled(final JFreeChart scatterPlot, final boolean enabled) { XYPlot plot = (XYPlot) scatterPlot.getPlot(); if (enabled) { StandardXYItemRenderer regressionRenderer = new StandardXYItemRenderer(); regressionRenderer.setBaseSeriesVisibleInLegend(false); plot.setDataset(1, regress((XYSeriesCollection) plot.getDataset(0))); plot.setRenderer(1, regressionRenderer); } else { plot.setDataset(1, null);//Remove linear regression } }
From source file:org.jfree.chart.demo.HighLowChartDemo3.java
private static JFreeChart createChart(OHLCDataset ohlcdataset) { JFreeChart jfreechart = ChartFactory.createHighLowChart("OHLC Demo 3", "Time", "Price", ohlcdataset, true); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); HighLowRenderer highlowrenderer = (HighLowRenderer) xyplot.getRenderer(); highlowrenderer.setBaseStroke(new BasicStroke(2.0F)); highlowrenderer.setSeriesPaint(0, Color.blue); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); NumberAxis numberaxis1 = new NumberAxis("Price 2"); numberaxis1.setAutoRangeIncludesZero(false); xyplot.setRangeAxis(1, numberaxis1); xyplot.setDataset(1, createDataset2()); xyplot.setRenderer(1, new CandlestickRenderer(10D)); xyplot.mapDatasetToRangeAxis(1, 1);//from w w w .ja v a 2 s . c o m ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
private static JFreeChart priceVolumeHistoryChart(String title, TimePeriodValuesCollection prices, TimePeriodValuesCollection volumes, boolean scalePrices) { JFreeChart chart = ChartFactory.createTimeSeriesChart(title, null, "Price", prices, false, false, false); XYPlot plot = chart.getXYPlot(); if (scalePrices) { setBoundsForPrice(chart);/*from w w w . j a va2s. com*/ } else { setBoundsForPercent(chart); } NumberAxis rangeAxis2 = new NumberAxis("Volume"); rangeAxis2.setUpperMargin(2); plot.setRangeAxis(1, rangeAxis2); plot.setDataset(1, volumes); plot.mapDatasetToRangeAxis(1, 1); XYBarRenderer renderer2 = new XYBarRenderer(0.2); plot.setRenderer(1, renderer2); return chart; }
From source file:ec.ui.view.DistributionView.java
private static JFreeChart createDistributionViewChart() { XYPlot plot = new XYPlot(); XYLineAndShapeRenderer dRenderer = new XYSplineRenderer(); dRenderer.setBaseShapesVisible(false); dRenderer.setAutoPopulateSeriesPaint(false); dRenderer.setAutoPopulateSeriesStroke(false); dRenderer.setBaseStroke(TsCharts.getStrongStroke(LinesThickness.Thin)); dRenderer.setDrawSeriesLineAsPath(true); // not sure if useful plot.setDataset(DISTRIBUTION_INDEX, Charts.emptyXYDataset()); plot.setRenderer(DISTRIBUTION_INDEX, dRenderer); XYBarRenderer hRenderer = new XYBarRenderer(); hRenderer.setShadowVisible(false);/*w w w.jav a 2 s. c o m*/ hRenderer.setDrawBarOutline(true); hRenderer.setAutoPopulateSeriesPaint(false); hRenderer.setAutoPopulateSeriesOutlinePaint(false); hRenderer.setBaseSeriesVisibleInLegend(false); plot.setDataset(HISTOGRAM_INDEX, Charts.emptyXYDataset()); plot.setRenderer(HISTOGRAM_INDEX, hRenderer); NumberAxis domainAxis = new NumberAxis(); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); plot.setDomainGridlinesVisible(false); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); rangeAxis.setTickUnit(new NumberTickUnit(0.05)); rangeAxis.setNumberFormatOverride(new DecimalFormat("0.###")); plot.setRangeAxis(rangeAxis); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); JFreeChart result = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); result.setPadding(TsCharts.CHART_PADDING); result.getTitle().setFont(TsCharts.CHART_TITLE_FONT); result.getLegend().setFrame(BlockBorder.NONE); result.getLegend().setBackgroundPaint(null); return result; }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Modify a scatter plot to show lines instead or shapes or not. * @param scatterPlot Scatter plot to modify * @param enabled Indicates if lines have to be shown *///from ww w . j a va2 s . co m public static void setScatterPlotLinesEnabled(final JFreeChart scatterPlot, final boolean enabled) { XYPlot plot = (XYPlot) scatterPlot.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); if (enabled) { renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); } else { renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1)); } renderer.setSeriesPaint(0, Color.RED); plot.setRenderer(0, renderer); }
From source file:org.jfree.chart.demo.CompareToPreviousYearDemo.java
private static JFreeChart createChart() { XYDataset xydataset = createDataset2006(); XYDataset xydataset1 = createDataset2007(); DateAxis dateaxis = new DateAxis("Date"); Month month = new Month(1, 2007); Month month1 = new Month(12, 2007); dateaxis.setRange(month.getFirstMillisecond(), month1.getLastMillisecond()); dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM")); dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); XYLineAndShapeRenderer xylineandshaperenderer = new XYLineAndShapeRenderer(); xylineandshaperenderer.setUseFillPaint(true); xylineandshaperenderer.setBaseFillPaint(Color.white); xylineandshaperenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}", new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot xyplot = new XYPlot(xydataset1, dateaxis, new NumberAxis("Sales"), xylineandshaperenderer); xyplot.setDomainPannable(true);/*from w ww. j a va 2 s . c o m*/ xyplot.setRangePannable(true); DateAxis dateaxis1 = new DateAxis(); dateaxis1.setVisible(false); xyplot.setDomainAxis(1, dateaxis1); xyplot.setDataset(1, xydataset); xyplot.mapDatasetToDomainAxis(1, 1); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); xylineandshaperenderer1.setSeriesPaint(0, Color.blue); xylineandshaperenderer1.setUseFillPaint(true); xylineandshaperenderer1.setBaseFillPaint(Color.white); xylineandshaperenderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{1}: {2}", new SimpleDateFormat("MMM-yyyy"), new DecimalFormat("0.00"))); xyplot.setRenderer(1, xylineandshaperenderer1); JFreeChart jfreechart = new JFreeChart("Sales Comparison Chart", xyplot); xyplot.setDomainCrosshairVisible(true); xyplot.setRangeCrosshairVisible(true); DateAxis dateaxis2 = (DateAxis) xyplot.getDomainAxis(); dateaxis2.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); ChartUtilities.applyCurrentTheme(jfreechart); return jfreechart; }
From source file:org.jfree.chart.demo.CompassFormatDemo1.java
private static JFreeChart createChart() { XYDataset xydataset = createDirectionDataset(600); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", xydataset, true, true, false);//from w w w . j a v a 2 s . c o m XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.getDomainAxis().setLowerMargin(0.0D); xyplot.getDomainAxis().setUpperMargin(0.0D); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); TickUnits tickunits = new TickUnits(); tickunits.add(new NumberTickUnit(180D, new CompassFormat())); tickunits.add(new NumberTickUnit(90D, new CompassFormat())); tickunits.add(new NumberTickUnit(45D, new CompassFormat())); tickunits.add(new NumberTickUnit(22.5D, new CompassFormat())); numberaxis.setStandardTickUnits(tickunits); xyplot.setRangeAxis(numberaxis); XYAreaRenderer xyarearenderer = new XYAreaRenderer(); NumberAxis numberaxis1 = new NumberAxis("Force"); numberaxis1.setRange(0.0D, 12D); xyarearenderer.setSeriesPaint(0, new Color(0, 0, 255, 128)); xyplot.setDataset(1, createForceDataset(600)); xyplot.setRenderer(1, xyarearenderer); xyplot.setRangeAxis(1, numberaxis1); xyplot.mapDatasetToRangeAxis(1, 1); return jfreechart; }
From source file:lu.lippmann.cdb.common.gui.ts.TimeSeriesChartUtil.java
private static void fillWithMultipleAxis(final Instances dataSet, final int dateIdx, final TimeSeriesCollection tsDataset, final JFreeChart tsChart) { final int numInstances = dataSet.numInstances(); int axisNumber = 0; final Calendar cal = Calendar.getInstance(); for (final Integer i : WekaDataStatsUtil.getNumericAttributesIndexes(dataSet)) { final TimeSeries ts = new TimeSeries(dataSet.attribute(i).name()); for (int k = 0; k < numInstances; k++) { final long timeInMilliSec = (long) dataSet.instance(k).value(dateIdx); cal.setTimeInMillis(timeInMilliSec); if (dataSet.instance(k).isMissing(i)) { ts.addOrUpdate(new Millisecond(cal.getTime()), null); } else { ts.addOrUpdate(new Millisecond(cal.getTime()), dataSet.instance(k).value(i)); }/*from w w w.j ava 2s .c o m*/ } if (!ts.isEmpty()) { if (axisNumber == 0) { tsDataset.addSeries(ts); } else { final XYPlot plot = tsChart.getXYPlot(); final NumberAxis axisToAdd = new NumberAxis(dataSet.attribute(i).name()); axisToAdd.setAutoRangeIncludesZero(false); plot.setRangeAxis(axisNumber, axisToAdd); final TimeSeriesCollection t = new TimeSeriesCollection(); t.addSeries(ts); plot.setDataset(axisNumber, t); plot.mapDatasetToRangeAxis(axisNumber, axisNumber); final StandardXYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setSeriesPaint(0, ColorHelper.getColorForAString(dataSet.attribute(i).name())); plot.setRenderer(axisNumber, renderer2); } axisNumber++; } } }
From source file:grafix.graficos.eixos.EixoExtra.java
private void prepararPlotVazio(final XYPlot plot) { StandardXYItemRenderer indicesRenderer = new StandardXYItemRenderer(); plot.setRenderer(0, indicesRenderer); }
From source file:org.jfree.chart.demo.XYLineAndShapeRendererDemo2.java
private static JFreeChart createChart() { XYDataset xydataset = createDataset(1, 1.0D); JFreeChart jfreechart = ChartFactory.createXYLineChart("XYLineAndShapeRenderer Demo 2", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false); jfreechart.setBackgroundPaint(Color.white); TextTitle texttitle = new TextTitle( "This chart shows various combinations of the useFillPaint and useOutlinePaint flags."); texttitle.setFont(new Font("Dialog", 0, 10)); jfreechart.addSubtitle(texttitle);// w ww . j a v a 2s . c om XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 8D, 8D); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylineandshaperenderer.setBaseShapesVisible(true); xylineandshaperenderer.setSeriesShape(0, double1); xylineandshaperenderer.setSeriesPaint(0, Color.red); xylineandshaperenderer.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer.setSeriesOutlinePaint(0, Color.gray); XYDataset xydataset1 = createDataset(2, 2D); XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(); xyplot.setDataset(1, xydataset1); xyplot.setRenderer(1, xylineandshaperenderer1); xylineandshaperenderer1.setSeriesShape(0, double1); xylineandshaperenderer1.setSeriesPaint(0, Color.red); xylineandshaperenderer1.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.gray); xylineandshaperenderer1.setUseFillPaint(true); XYDataset xydataset2 = createDataset(3, 3D); XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); xyplot.setDataset(2, xydataset2); xyplot.setRenderer(2, xylineandshaperenderer2); xylineandshaperenderer2.setSeriesShape(0, double1); xylineandshaperenderer2.setSeriesPaint(0, Color.red); xylineandshaperenderer2.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.gray); xylineandshaperenderer2.setUseOutlinePaint(true); XYDataset xydataset3 = createDataset(4, 4D); XYLineAndShapeRenderer xylineandshaperenderer3 = new XYLineAndShapeRenderer(); xyplot.setDataset(3, xydataset3); xyplot.setRenderer(3, xylineandshaperenderer3); xylineandshaperenderer3.setSeriesShape(0, double1); xylineandshaperenderer3.setSeriesPaint(0, Color.red); xylineandshaperenderer3.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer3.setSeriesOutlinePaint(0, Color.gray); xylineandshaperenderer3.setUseOutlinePaint(true); xylineandshaperenderer3.setUseFillPaint(true); XYDataset xydataset4 = createDataset(5, 5D); XYLineAndShapeRenderer xylineandshaperenderer4 = new XYLineAndShapeRenderer(); xyplot.setDataset(4, xydataset4); xyplot.setRenderer(4, xylineandshaperenderer4); xylineandshaperenderer4.setSeriesShape(0, double1); xylineandshaperenderer4.setSeriesPaint(0, Color.red); xylineandshaperenderer4.setSeriesFillPaint(0, Color.yellow); xylineandshaperenderer4.setSeriesOutlinePaint(0, Color.gray); xylineandshaperenderer4.setUseOutlinePaint(true); xylineandshaperenderer4.setUseFillPaint(true); xylineandshaperenderer4.setDrawOutlines(false); return jfreechart; }