List of usage examples for org.jfree.chart.plot XYPlot setRenderer
public void setRenderer(XYItemRenderer renderer)
From source file:org.jfree.chart.demo.SymbolicXYPlotDemo.java
/** * Creates a XY graph with symbolic value on X and Y axis. * /*from w w w . j a v a2 s . c om*/ * @param title * the title. * @param xAxisLabel * the x axis label. * @param yAxisLabel * the y axis label. * @param data * the dataset. * @param legend * create a legend? * @return a chart. */ public static JFreeChart createXYSymbolicPlot(final String title, final String xAxisLabel, final String yAxisLabel, final XYDataset data, final boolean legend) { final SymbolicAxis xSymbolicAxis = new SymbolicAxis(xAxisLabel, ((XisSymbolic) data).getXSymbolicValues()); final SymbolicAxis ySymbolicAxis = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data).getYSymbolicValues()); final XYPlot plot = new XYPlot(data, xSymbolicAxis, ySymbolicAxis, null); final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, new SymbolicXYItemLabelGenerator()); plot.setRenderer(renderer); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:com.spotify.heroic.http.render.RenderUtils.java
public static JFreeChart createChart(final List<ShardedResultGroup> groups, final String title, Map<String, String> highlight, Double threshold, int height) { final XYLineAndShapeRenderer lineAndShapeRenderer = new XYLineAndShapeRenderer(true, true); final DeviationRenderer intervalRenderer = new DeviationRenderer(); final XYSeriesCollection regularData = new XYSeriesCollection(); final YIntervalSeriesCollection intervalData = new YIntervalSeriesCollection(); int lineAndShapeCount = 0; int intervalCount = 0; for (final ShardedResultGroup resultGroup : groups) { final MetricCollection group = resultGroup.getMetrics(); if (group.getType() == MetricType.POINT) { final XYSeries series = new XYSeries(resultGroup.getMetrics().toString()); final List<Point> data = group.getDataAs(Point.class); for (final Point d : data) { series.add(d.getTimestamp(), d.getValue()); }/*from w ww . j av a 2 s . c o m*/ lineAndShapeRenderer.setSeriesPaint(lineAndShapeCount, Color.BLUE); lineAndShapeRenderer.setSeriesShapesVisible(lineAndShapeCount, false); lineAndShapeRenderer.setSeriesStroke(lineAndShapeCount, new BasicStroke(2.0f)); regularData.addSeries(series); ++lineAndShapeCount; } if (group.getType() == MetricType.SPREAD) { final YIntervalSeries series = new YIntervalSeries(resultGroup.getMetrics().toString()); final List<Spread> data = group.getDataAs(Spread.class); for (final Spread d : data) { series.add(d.getTimestamp(), d.getSum() / d.getCount(), d.getMin(), d.getMax()); } intervalRenderer.setSeriesPaint(intervalCount, Color.GREEN); intervalRenderer.setSeriesStroke(intervalCount, new BasicStroke(2.0f)); intervalRenderer.setSeriesFillPaint(intervalCount, new Color(200, 255, 200)); intervalRenderer.setSeriesShapesVisible(intervalCount, false); intervalData.addSeries(series); ++intervalCount; } } final JFreeChart chart = buildChart(title, regularData, intervalData, lineAndShapeRenderer, intervalRenderer); chart.setAntiAlias(true); chart.setBackgroundPaint(Color.WHITE); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.BLACK); plot.setRangeGridlinePaint(Color.BLACK); if (threshold != null) { final ValueMarker marker = new ValueMarker(threshold, Color.RED, new BasicStroke(Math.max(Math.min(height / 20, 6), 1)), Color.RED, null, 0.5f); plot.addRangeMarker(marker); } plot.setRenderer(lineAndShapeRenderer); // final DateAxis rangeAxis = (DateAxis) plot.getRangeAxis(); // rangeAxis.setStandardTickUnits(DateAxis.createStandardDateTickUnits()); return chart; }
From source file:org.gaixie.micrite.jfreechart.style.LineStyle.java
public static void styleOne(JFreeChart chart) { XYPlot xyplot = (XYPlot) chart.getPlot(); XYDataset xyd = xyplot.getDataset(); //?/*w ww.j a v a 2 s . c o m*/ LineStyle.setBackground(chart); XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); if (xyd != null) { //? xylineandshaperenderer.setBaseShapesVisible(true); // xylineandshaperenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer.setBaseItemLabelsVisible(true); xyplot.setRenderer(xylineandshaperenderer); //tooltip // xyplot.getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}: ({1}, {2})",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"),new DecimalFormat())); //? for (int i = 0; i < xyd.getSeriesCount(); i++) { int colorIdx = i % colors.length; xylineandshaperenderer.setSeriesPaint(i, colors[colorIdx]); } } else { xyplot.setNoDataMessage("NO DATA"); } }
From source file:org.jfree.chart.demo.XYStepRendererDemo2.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart jfreechart = ChartFactory.createXYLineChart("XYStepRenderer Demo 2", "X", "Y", xydataset, PlotOrientation.VERTICAL, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); ValueAxis valueaxis = xyplot.getRangeAxis(); valueaxis.setUpperMargin(0.14999999999999999D); XYStepRenderer xysteprenderer = new XYStepRenderer(); xysteprenderer.setSeriesStroke(0, new BasicStroke(2.0F)); xysteprenderer.setSeriesStroke(1, new BasicStroke(2.0F)); xysteprenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); xysteprenderer.setDefaultEntityRadius(6); xysteprenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xysteprenderer.setBaseItemLabelsVisible(true); xysteprenderer.setBaseItemLabelFont(new Font("Dialog", 1, 14)); xyplot.setRenderer(xysteprenderer); return jfreechart; }
From source file:FindHullWindowLogic.java
static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull) { panelWhenInside.removeAll();//from ww w . ja va 2 s . com panelWhenInside.setLayout(new java.awt.BorderLayout()); XYSeries seriersAllPoints = new XYSeries("All points"); addPointsToSeries(seriersAllPoints); int pairsNumber = 0; if (convexHull != null) pairsNumber = convexHull.size() - 1; XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber]; for (int i = 0; i < covnexHullDivideOnPiars.length; i++) { covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i); } if (convexHull != null) { divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull); } // Add the seriersAllPoints to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(seriersAllPoints); for (int i = 0; i < covnexHullDivideOnPiars.length; i++) { dataset.addSeries(covnexHullDivideOnPiars[i]); } // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart(null, // Title null, // x-axis Label null, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend false, // Use tooltips false // Configure chart to generate URLs? ); final XYPlot plot = chart.getXYPlot(); ChartPanel chartPanel = new ChartPanel(chart); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3)); for (int i = 1; i <= covnexHullDivideOnPiars.length; i++) { renderer.setSeriesPaint(i, Color.red); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesStroke(i, new BasicStroke(1.0f)); } plot.setRenderer(renderer); panelWhenInside.add(chartPanel, BorderLayout.CENTER); panelWhenInside.validate(); }
From source file:org.jfree.chart.demo.DeviationRendererDemo2.java
private static JFreeChart createChart(XYDataset xydataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart("Projected Values - Test", "Date", "Index Projection", xydataset, true, true, false); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setInsets(new RectangleInsets(5D, 5D, 5D, 20D)); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); ////from w w w . jav a 2 s.c o m DeviationRenderer renderer = new DeviationRenderer(true, false); renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); renderer.setSeriesStroke(0, new BasicStroke(3F, 1, 1)); renderer.setSeriesStroke(1, new BasicStroke(3F, 1, 1)); renderer.setSeriesFillPaint(0, new Color(255, 200, 200)); renderer.setSeriesFillPaint(1, new Color(200, 200, 255)); plot.setRenderer(renderer); // NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis(); valueAxis.setAutoRangeIncludesZero(false); valueAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaChartExpression.java
public static JFreeChart createTimeSeriesChart(final String title, final String timeAxisLabel, final String valueAxisLabel, final XYDataset dataset, final boolean legend, final boolean tooltips, final boolean urls, final boolean stacked) { final ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02);//from w ww .j av a 2 s .c o m final NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default final XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); } XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } final XYAreaRenderer2 renderer; if (stacked) { renderer = new StackedXYAreaRenderer2(); } else { renderer = new XYAreaRenderer2(); } renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); plot.setRenderer(renderer); return new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); }
From source file:dumbara.view.Chart1.java
public static void ViewLineChart(String[] agencyID, String[] sslesDate, ArrayList<String[]> arrayList) throws SQLException, ClassNotFoundException { XYSeries series1 = new XYSeries("Agency 1"); XYSeries series2 = new XYSeries("Agency 2"); XYSeries series3 = new XYSeries("Agency 3"); XYSeries series4 = new XYSeries("Agency 4"); for (String[] strings : arrayList) { for (int i = 0; i < sslesDate.length; i++) { System.out.println(sslesDate[i].split("-")[1] + ""); series1.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(0)[i])); }/* w ww.j a v a2 s . c o m*/ for (int i = 0; i < sslesDate.length; i++) { series2.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(1)[i])); } for (int i = 0; i < sslesDate.length; i++) { series3.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(2)[i])); } for (int i = 0; i < sslesDate.length; i++) { series4.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(3)[i])); } } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); dataset.addSeries(series3); dataset.addSeries(series4); XYDataset dataset1 = dataset; JFreeChart chart = ChartFactory.createXYLineChart("", "Test Id", "Average Marks", dataset1, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(1, true); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(2, true); renderer.setSeriesShapesVisible(2, true); renderer.setSeriesFillPaint(2, Color.MAGENTA); plot.setRenderer(renderer); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); //(chartPanel); ChartFrame frame = new ChartFrame("Dumbara Water Management System", chart); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); }
From source file:org.matsim.contrib.dvrp.util.chart.ScheduleCharts.java
public static JFreeChart chartSchedule(Collection<? extends Vehicle> vehicles, DescriptionCreator descriptionCreator, PaintSelector paintSelector) { // data/*from ww w . jav a 2 s .c om*/ TaskSeriesCollection dataset = createScheduleDataset(vehicles, descriptionCreator); XYTaskDataset xyTaskDataset = new XYTaskDataset(dataset); // chart JFreeChart chart = ChartFactory.createXYBarChart("Schedules", "Time", false, "Vehicles", xyTaskDataset, PlotOrientation.HORIZONTAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); // Y axis String[] series = new String[vehicles.size()]; int i = 0; for (Vehicle v : vehicles) { series[i++] = v.getId().toString(); } SymbolAxis symbolAxis = new SymbolAxis("Vehicles", series); symbolAxis.setGridBandsVisible(false); plot.setDomainAxis(symbolAxis); // X axis plot.setRangeAxis(new DateAxis("Time", TimeZone.getTimeZone("GMT"), Locale.getDefault())); // Renderer XYBarRenderer xyBarRenderer = new ChartTaskRenderer(dataset, paintSelector); xyBarRenderer.setUseYInterval(true); plot.setRenderer(xyBarRenderer); return chart; }
From source file:org.matsim.contrib.dvrp.util.chart.ScheduleChartUtils.java
public static <T extends Task> JFreeChart chartSchedule(List<? extends Vehicle> vehicles, DescriptionCreator<T> descriptionCreator, PaintSelector<T> paintSelector) { // data/*www . ja v a 2s . c o m*/ TaskSeriesCollection dataset = createScheduleDataset(vehicles, descriptionCreator); XYTaskDataset xyTaskDataset = new XYTaskDataset(dataset); // chart JFreeChart chart = ChartFactory.createXYBarChart("Schedules", "Time", false, "Vehicles", xyTaskDataset, PlotOrientation.HORIZONTAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); // Y axis String[] series = new String[vehicles.size()]; for (int i = 0; i < series.length; i++) { series[i] = vehicles.get(i).getId().toString(); } SymbolAxis symbolAxis = new SymbolAxis("Vehicles", series); symbolAxis.setGridBandsVisible(false); plot.setDomainAxis(symbolAxis); // X axis plot.setRangeAxis(new DateAxis("Time", TimeZone.getTimeZone("GMT"), Locale.getDefault())); // Renderer XYBarRenderer xyBarRenderer = new ChartTaskRenderer<T>(dataset, paintSelector); xyBarRenderer.setUseYInterval(true); plot.setRenderer(xyBarRenderer); return chart; }