/** * Builds and returns JFreeChart. * * @return */ public JFreeChart build() { XYSeriesCollection collection = new XYSeriesCollection(); for (XYSeries s : seriesMap.values()) { collection.addSeries(s); } JFreeChart chart = ChartFactory.createXYLineChart(chartName, xDomain, yDomain, collection, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); return chart; }
chart.getXYPlot().setDomainGridlinePaint(new Color(gridColor)); chart.getXYPlot().setRangeGridlinePaint(new Color(gridColor)); chart.getXYPlot().setDomainAxis(0, new DateAxis());
private XYPlot createPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, XYSeriesCollection solution) { XYPlot plot = new XYPlot(); plot.setBackgroundPaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); XYLineAndShapeRenderer problemRenderer = getProblemRenderer(problem); plot.setDataset(0, problem); plot.setRenderer(0, problemRenderer); XYItemRenderer shipmentsRenderer = getShipmentRenderer(shipments); plot.setDataset(1, shipments); plot.setRenderer(1, shipmentsRenderer); if (solution != null) { XYItemRenderer solutionRenderer = getRouteRenderer(solution); plot.setDataset(2, solution); plot.setRenderer(2, solutionRenderer); } NumberAxis xAxis = new NumberAxis(); NumberAxis yAxis = new NumberAxis(); if (boundingBox == null) { xAxis.setRangeWithMargins(getDomainRange(problem)); yAxis.setRangeWithMargins(getRange(problem)); } else { xAxis.setRangeWithMargins(new Range(boundingBox.minX, boundingBox.maxX)); yAxis.setRangeWithMargins(new Range(boundingBox.minY, boundingBox.maxY)); } plot.setDomainAxis(xAxis); plot.setRangeAxis(yAxis); return plot; }
@Override protected void setSpecialColors() { XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinePaint(ChartColorFactory.createColor(ofxChart, ChartColorFactory.Area.gridRange)); plot.setDomainGridlinePaint(ChartColorFactory.createColor(ofxChart, ChartColorFactory.Area.gridDomain)); }
public XYChartBuilder(final JFreeChart chart) { this.chart = chart; plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setOutlineVisible(false); }
private JFreeChart createChart() { final XYDataset dataset = this.createDataset(series); final JFreeChart result = ChartFactory.createTimeSeriesChart("Dynamic Line And TimeSeries Chart", "Time", "Value", dataset, true, true, false); final XYPlot plot = result.getXYPlot(); plot.setBackgroundPaint(new Color(0xffffe0)); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // first time series this.firstTimeSeries(plot); // second time series this.secondTimeSeries(plot); // third time series this.thirdTimeSeries(plot); return result; }
/** * Builds and returns JFreeChart. * * @return */ public JFreeChart build() { XYSeriesCollection collection = new XYSeriesCollection(); for (XYSeries s : seriesMap.values()) { collection.addSeries(s); } JFreeChart chart = ChartFactory.createXYLineChart(chartName, xDomain, yDomain, collection, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); return chart; }
public static void decorateChart(JFreeChart chart) { XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 2, 2)); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setDomainGridlinePaint(java.awt.Color.GRAY); plot.setRangeGridlinePaint(java.awt.Color.GRAY); plot.setRenderer(renderer); }
public void drawChart(String filename, int width, int height) throws IOException { // Create plot NumberAxis xAxis = new NumberAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYSplineRenderer renderer = new XYSplineRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); // Create chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartUtilities.applyCurrentTheme(chart); ChartPanel chartPanel = new ChartPanel(chart, false); // Draw png BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Graphics graphics = bi.getGraphics(); chartPanel.setBounds(0, 0, width, height); chartPanel.paint(graphics); ImageIO.write(bi, "png", new File(filename)); }
public void drawChart(String filename, int width, int height) throws IOException { // Create plot NumberAxis xAxis = new NumberAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYSplineRenderer renderer = new XYSplineRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); // Create chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, true); ChartUtilities.applyCurrentTheme(chart); ChartPanel chartPanel = new ChartPanel(chart, false); // Draw png BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR); Graphics graphics = bi.getGraphics(); chartPanel.setBounds(0, 0, width, height); chartPanel.paint(graphics); ImageIO.write(bi, "png", new File(filename)); }
public static JFreeChart getStepChart(String title, TSContainer2 container) { TimeSeriesCollection tempDataSet = new TimeSeriesCollection(); for (int i = 0; i < container.getNumColumns(); i++) { DoubleColumn dc = (DoubleColumn) container.getColumns().get(i); List<TimeStamp> ts = container.getTimeStamps(); TimeSeries tsNew = new TimeSeries(container.getColumnHeaders().get(i)); for (int j = 0; j < dc.size(); j++) tsNew.addOrUpdate(new Millisecond(ts.get(j).getDate()), dc.get(j)); // add a new series. tempDataSet.addSeries(tsNew); } JFreeChart chart = ChartFactory.createXYStepChart(title, "Time", "Value", tempDataSet, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.WHITE); chart.getPlot().setBackgroundPaint(Color.WHITE); ((XYPlot)chart.getPlot()).setDomainGridlinePaint(Color.LIGHT_GRAY); ((XYPlot)chart.getPlot()).setRangeGridlinePaint(Color.LIGHT_GRAY); return chart; } }
private static TimeSeriesCollection addSubPlot(CombinedDomainXYPlot plot, String label) { final TimeSeriesCollection seriesCollection = new TimeSeriesCollection(new TimeSeries(label, Millisecond.class)); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot = new XYPlot(seriesCollection, null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); return seriesCollection; }
private static TimeSeriesCollection addSubPlot(CombinedDomainXYPlot plot, String label) { final TimeSeriesCollection seriesCollection = new TimeSeriesCollection(new TimeSeries(label, Millisecond.class)); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); XYPlot subplot = new XYPlot(seriesCollection, null, rangeAxis, new StandardXYItemRenderer()); subplot.setBackgroundPaint(Color.lightGray); subplot.setDomainGridlinePaint(Color.white); subplot.setRangeGridlinePaint(Color.white); plot.add(subplot); return seriesCollection; }
private XYPlot createPlotArea(JFreeChart chart) { XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); showCrosshairsOnAxes(plot); configureDomainAxis(plot); showGridlinesOnChart(plot); configureTimeAxis(plot); configureTitle(chart); addNotice(chart); return plot; }
/** * Creates a chart. * * @param dataset * a dataset. * * @return A chart. */ private JFreeChart createChart(SimpleHistogramDataset dataset) { chart = ChartFactory.createHistogram(null, engl("Value"), engl("Histogram"), dataset, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.getRenderer().setSeriesPaint(0, new Color(0x7f9f51)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); return chart; }
private XYPlot createPlotArea(JFreeChart chart) { XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(WHITE); plot.setDomainGridlinePaint(LIGHT_GRAY); plot.setRangeGridlinePaint(LIGHT_GRAY); plot.setAxisOffset(new RectangleInsets(2.0, 2.0, 2.0, 2.0)); showCrosshairsOnAxes(plot); configureDomainAxis(plot); showGridlinesOnChart(plot); configureTimeAxis(plot); configureTitle(chart); addNotice(chart); return plot; }
static private final void setBackgroundDefault(final JFreeChart chart) { BasicStroke gridStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[]{2.0f, 1.0f}, 0.0f); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlineStroke(gridStroke); plot.setDomainGridlineStroke(gridStroke); plot.setBackgroundPaint(new Color(235, 235, 235)); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setOutlineVisible(false); plot.getDomainAxis().setAxisLineVisible(false); plot.getRangeAxis().setAxisLineVisible(false); plot.getDomainAxis().setLabelPaint(Color.gray); plot.getRangeAxis().setLabelPaint(Color.gray); plot.getDomainAxis().setTickLabelPaint(Color.gray); plot.getRangeAxis().setTickLabelPaint(Color.gray); chart.getTitle().setPaint(Color.gray); } }
public void enableGrid(boolean enable) { if (enable) { BasicStroke dotted = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] {1.0f, 6.0f}, 0.0f); graph.getXYPlot().setDomainGridlinesVisible(true); graph.getXYPlot().setRangeGridlinesVisible(true); graph.getXYPlot().setRangeGridlinePaint(Color.black); graph.getXYPlot().setDomainGridlinePaint(Color.black); graph.getXYPlot().setRangeGridlineStroke(dotted); graph.getXYPlot().setDomainGridlineStroke(dotted); } else { graph.getXYPlot().setDomainGridlinesVisible(false); graph.getXYPlot().setRangeGridlinesVisible(false); } }
private final void setBackgroundDefault(final JFreeChart chart) { final BasicStroke gridStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 1.0f }, 0.0f); final XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlineStroke(gridStroke); plot.setDomainGridlineStroke(gridStroke); plot.setBackgroundPaint(new Color(235, 235, 235)); plot.setRangeGridlinePaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setOutlineVisible(false); plot.getDomainAxis().setAxisLineVisible(false); plot.getRangeAxis().setAxisLineVisible(false); plot.getDomainAxis().setLabelPaint(Color.gray); plot.getRangeAxis().setLabelPaint(Color.gray); plot.getDomainAxis().setTickLabelPaint(Color.gray); plot.getRangeAxis().setTickLabelPaint(Color.gray); final TextTitle title = chart.getTitle(); if (title != null) title.setPaint(Color.black); }
/** * Updates the axis-related properties of a plot. * * @param aPlot * Plot to be updated. * @param aAxes * Axis-related visual settings to be applied. * @param aGrid * Grid-related visual settings to be applied. */ private static void updateAxes(XYPlot aPlot, AxesSettings aAxes, GridSettings aGrid, Range aDomainDataRange, Range aRangeDataRange) { aPlot.setDomainAxis(createAxis(aAxes, true, aDomainDataRange)); aPlot.setRangeAxis(createAxis(aAxes, false, aRangeDataRange)); aPlot.setDomainGridlinesVisible(aGrid.getVerticalGridLines()); // set gridlines for X axis aPlot.setDomainGridlinePaint(aGrid.getGridLinesColor()); // set color of domain gridline aPlot.setRangeGridlinesVisible(aGrid.getHorizontalGridLines()); // set gridlines for Y axis aPlot.setRangeGridlinePaint(aGrid.getGridLinesColor()); // set color of range gridline }