List of usage examples for org.jfree.chart.plot XYPlot setDomainGridlinesVisible
public void setDomainGridlinesVisible(boolean visible)
From source file:eu.choreos.vv.chart.YIntervalChart.java
private static JFreeChart createChart(XYDataset dataset, String chartTitle, String xLabel, String yLabel) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // initial series PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );/*from w ww .j a v a2 s .c o m*/ // set chart background chart.setBackgroundPaint(Color.white); // set a few custom plot features XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(new Color(0xffffe0)); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); // set the plot's axes to display integers TickUnitSource ticks = NumberAxis.createIntegerTickUnits(); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setStandardTickUnits(ticks); domain.resizeRange(1.1); domain.setLowerBound(0.5); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setStandardTickUnits(ticks); range.setUpperBound(range.getUpperBound() * 1.1); // render shapes and lines DeviationRenderer renderer = new DeviationRenderer(true, true); plot.setRenderer(renderer); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // set the renderer's stroke Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL); renderer.setBaseOutlineStroke(stroke); //TODO: render the deviation with the same color as the line // renderer.setBaseFillPaint(new Color(255, 200, 200)); // renderer.setUseOutlinePaint(flag); // renderer.setUseFillPaint(flag); // label the points NumberFormat format = NumberFormat.getNumberInstance(); format.setMaximumFractionDigits(2); XYItemLabelGenerator generator = new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format); renderer.setBaseItemLabelGenerator(generator); renderer.setBaseItemLabelsVisible(true); //TODO: fix the visible area to show the deviation return chart; }
From source file:org.jfree.chart.demo.XIntervalSeriesCollectionDemo1.java
private static JFreeChart createChart(IntervalXYDataset intervalxydataset) { DateAxis dateaxis = new DateAxis("Date"); NumberAxis numberaxis = new NumberAxis("Y"); XYBarRenderer xybarrenderer = new XYBarRenderer(); xybarrenderer.setUseYInterval(true); XYPlot xyplot = new XYPlot(intervalxydataset, dateaxis, numberaxis, xybarrenderer); JFreeChart jfreechart = new JFreeChart(xyplot); jfreechart.setBackgroundPaint(Color.white); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.white); return jfreechart; }
From source file:org.matsim.contrib.dvrp.util.chart.RouteChartUtils.java
public static JFreeChart chartRoutesByStatus(List<? extends Vehicle> vehicles) { CoordDataset nData = new CoordDataset(); for (int i = 0; i < vehicles.size(); i++) { Schedule<?> schedule = vehicles.get(i).getSchedule(); Map<TaskStatus, CoordSource> vsByStatus = createLinkSourceByStatus(schedule); nData.addSeries(i + "-PR", vsByStatus.get(TaskStatus.PERFORMED)); nData.addSeries(i + "-ST", vsByStatus.get(TaskStatus.STARTED)); nData.addSeries(i + "-PL", vsByStatus.get(TaskStatus.PLANNED)); }//from w w w . j av a 2s. co m JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", nData, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setBackgroundPaint(Color.white); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setAutoRangeIncludesZero(false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesItemLabelsVisible(0, true); renderer.setBaseItemLabelGenerator(new LabelGenerator()); Paint[] paints = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE; Shape[] shapes = DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE; for (int i = 0; i < vehicles.size(); i++) { int s = 3 * i; renderer.setSeriesItemLabelsVisible(s + 1, true); renderer.setSeriesItemLabelsVisible(s + 2, true); renderer.setSeriesItemLabelsVisible(s + 3, true); renderer.setSeriesShapesVisible(s + 1, true); renderer.setSeriesShapesVisible(s + 2, true); renderer.setSeriesShapesVisible(s + 3, true); renderer.setSeriesLinesVisible(s + 1, true); renderer.setSeriesLinesVisible(s + 2, true); renderer.setSeriesLinesVisible(s + 3, true); renderer.setSeriesPaint(s + 1, paints[(i + 1) % paints.length]); renderer.setSeriesPaint(s + 2, paints[(i + 1) % paints.length]); renderer.setSeriesPaint(s + 3, paints[(i + 1) % paints.length]); renderer.setSeriesShape(s + 1, shapes[(i + 1) % shapes.length]); renderer.setSeriesShape(s + 2, shapes[(i + 1) % shapes.length]); renderer.setSeriesShape(s + 3, shapes[(i + 1) % shapes.length]); renderer.setSeriesStroke(s + 2, new BasicStroke(3)); renderer.setSeriesStroke(s + 3, new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] { 5f, 5f }, 0)); } return chart; }
From source file:com.projity.pm.graphic.chart.ChartHelper.java
public static void removeAxisAndInsets(XYPlot plot) { plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setVisible(false); plot.setDomainGridlinesVisible(false); plot.setInsets(new RectangleInsets(0, 0, BOTTOM_INSET, 0)); }
From source file:org.matsim.contrib.dvrp.util.chart.RouteCharts.java
public static JFreeChart chartRoutesByStatus(List<? extends Vehicle> vehicles) { CoordDataset nData = new CoordDataset(); for (int i = 0; i < vehicles.size(); i++) { Schedule schedule = vehicles.get(i).getSchedule(); Map<TaskStatus, CoordSource> vsByStatus = createLinkSourceByStatus(schedule); nData.addSeries(i + "-PR", vsByStatus.get(TaskStatus.PERFORMED)); nData.addSeries(i + "-ST", vsByStatus.get(TaskStatus.STARTED)); nData.addSeries(i + "-PL", vsByStatus.get(TaskStatus.PLANNED)); }// w ww . j a v a2s .c o m JFreeChart chart = ChartFactory.createXYLineChart("Routes", "X", "Y", nData, PlotOrientation.VERTICAL, false, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeGridlinesVisible(false); plot.setDomainGridlinesVisible(false); plot.setBackgroundPaint(Color.white); NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setAutoRangeIncludesZero(false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesItemLabelsVisible(0, true); renderer.setBaseItemLabelGenerator(new LabelGenerator()); Paint[] paints = DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE; Shape[] shapes = DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE; for (int i = 0; i < vehicles.size(); i++) { int s = 3 * i; renderer.setSeriesItemLabelsVisible(s + 1, true); renderer.setSeriesItemLabelsVisible(s + 2, true); renderer.setSeriesItemLabelsVisible(s + 3, true); renderer.setSeriesShapesVisible(s + 1, true); renderer.setSeriesShapesVisible(s + 2, true); renderer.setSeriesShapesVisible(s + 3, true); renderer.setSeriesLinesVisible(s + 1, true); renderer.setSeriesLinesVisible(s + 2, true); renderer.setSeriesLinesVisible(s + 3, true); renderer.setSeriesPaint(s + 1, paints[(i + 1) % paints.length]); renderer.setSeriesPaint(s + 2, paints[(i + 1) % paints.length]); renderer.setSeriesPaint(s + 3, paints[(i + 1) % paints.length]); renderer.setSeriesShape(s + 1, shapes[(i + 1) % shapes.length]); renderer.setSeriesShape(s + 2, shapes[(i + 1) % shapes.length]); renderer.setSeriesShape(s + 3, shapes[(i + 1) % shapes.length]); renderer.setSeriesStroke(s + 2, new BasicStroke(3)); renderer.setSeriesStroke(s + 3, new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] { 5f, 5f }, 0)); } return chart; }
From source file:org.spf4j.perf.impl.chart.Charts.java
public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values, final long startTimeMillis, final long stepMillis, final String uom, final String chartName) { final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis, stepMillis);/*w w w. j a v a 2s . c o m*/ NumberAxis xAxis = new NumberAxis("Time"); xAxis.setStandardTickUnits(dataSet.createXTickUnits()); xAxis.setLowerMargin(0); xAxis.setUpperMargin(0); xAxis.setVerticalTickLabels(true); NumberAxis yAxis = new NumberAxis(uom); yAxis.setStandardTickUnits(dataSet.createYTickUnits()); yAxis.setLowerMargin(0); yAxis.setUpperMargin(0); XYBlockRenderer renderer = new XYBlockRenderer(); PaintScale scale; if (dataSet.getMinValue() >= dataSet.getMaxValue()) { if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) { scale = new InverseGrayScale(0, 1); } else { scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1); } } else { scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue()); } renderer.setPaintScale(scale); renderer.setBlockWidth(1); renderer.setBlockHeight(1); XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setRangeMinorGridlinesVisible(false); JFreeChart chart = new JFreeChart(chartName, plot); PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count")); legend.setMargin(0, 5, 0, 5); chart.addSubtitle(legend); chart.removeLegend(); chart.setBackgroundPaint(Color.white); return chart; }
From source file:com.javafxpert.neuralnetviz.scenario.PlotUtil.java
private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints, XYDataset xyData) {/* w ww . j a va 2 s . c om*/ NumberAxis xAxis = new NumberAxis("X"); xAxis.setRange(mins[0], maxs[0]); NumberAxis yAxis = new NumberAxis("Y"); yAxis.setRange(mins[1], maxs[1]); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth((maxs[0] - mins[0]) / (nPoints - 1)); renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1)); PaintScale scale = new GrayPaintScale(0, 1.0); renderer.setPaintScale(scale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart chart = new JFreeChart("", plot); chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false); NumberAxis scaleAxis = new NumberAxis("Probability (class 0)"); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7)); PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(), scaleAxis); legend.setStripOutlineVisible(false); legend.setSubdivisionCount(20); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5.0); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setFrame(new BlockBorder(Color.red)); legend.setPadding(new RectangleInsets(10, 10, 10, 10)); legend.setStripWidth(10); legend.setPosition(RectangleEdge.LEFT); chart.addSubtitle(legend); ChartUtilities.applyCurrentTheme(chart); plot.setDataset(1, xyData); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setBaseLinesVisible(false); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:org.cyberoam.iview.charts.XYLine.java
/** * This method generates JFreeChart instance for XYLine chart with iView customization. * @param reportID specifies that for which report Chart is being prepared. * @param rsw specifies data set which would be used for the Chart * @param requeest used for Hyperlink generation from URL. * @return jfreechart instance with iView Customization. */// ww w .j av a 2 s. c om public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) { ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID); JFreeChart chart = null; try { ReportColumnBean reportColumnBean = null; GraphBean graphBean = null; DataLinkBean dataLinkBean = null; XYDataset dataset = null; XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYSeries series = new XYSeries(reportBean.getTitle()); graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getXColumnId());//getting ReportColumnBean For X Axis String xColumnDBname = reportColumnBean.getDbColumnName(); String xColumnName = reportColumnBean.getColumnName(); //Wheather DataLink is Given For X Axis column if (reportColumnBean.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId()); } reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getYColumnId()); String yColumnDBname = reportColumnBean.getDbColumnName(); String yColumnName = reportColumnBean.getColumnName(); //if DataLink is not Given For X Axis column then Check of Y Axis Column if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) { dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId()); } reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getZColumnId()); String zColumnDbname = reportColumnBean.getDbColumnName(); //Preparing DataSet String data = ""; rsw.beforeFirst(); while (rsw.next()) { data = rsw.getString(xColumnDBname); series.add(Long.parseLong((data).substring(data.length() - 2)), new Long(rsw.getLong(yColumnDBname)).longValue()); } seriesCollection.addSeries(series); dataset = seriesCollection; // create the chart... chart = ChartFactory.createXYLineChart("", // chart title "", // domain axis label "", seriesCollection, // data PlotOrientation.VERTICAL, // orientation false, // include legend true, // tooltips? false // URLs? ); /* * Additional iView Customization. */ //Set the background color for the chart... chart.setBackgroundPaint(Color.white); //Get a reference to the plot for further customisation... XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(new Color(245, 245, 245)); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setForegroundAlpha(0.7f); //Set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); if (reportColumnBean.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) { rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4)); } rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10)); rangeAxis.setTickLabelsVisible(true); rangeAxis.setTickMarksVisible(false); rangeAxis.setAxisLineVisible(false); Axis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10)); domainAxis.setTickMarksVisible(false); domainAxis.setAxisLineVisible(false); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.DARK_GRAY); renderer.setSeriesStroke(0, new BasicStroke(1)); } catch (Exception e) { e.printStackTrace(); } return chart; }
From source file:eu.kprod.gui.chart.MwChartFactory.java
public static MwChartPanel createChart(MwConfiguration conf, final XYDataset xyDataset) { final JFreeChart chart; chart = ChartFactory.createTimeSeriesChart(null, null, null, xyDataset, false, true, true); chart.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR)); chart.setBorderVisible(false);// w w w . j a v a 2 s .c o m final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR)); plot.setDomainGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setRangeGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("mm''ss''''SSS")); axis.setAxisLineVisible(false); axis.setTickLabelsVisible(false); axis.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); // force integer display final ValueAxis va = plot.getRangeAxis(); va.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); va.setLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); va.setAxisLinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); va.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); // va.setRange(-280,280); // va.setFixedAutoRange(560); // va.setLowerBound(-280); // va.setUpperBound(280); // va.setAutoRange(false); va.setRangeWithMargins(-280, 280); final MwChartPanel chartPanel = new MwChartPanel(chart, conf); chartPanel.setMouseWheelEnabled(false); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); return chartPanel; }
From source file:org.multiwii.swingui.gui.chart.MwChartFactory.java
public static MwChartPanel createChart(MwConfiguration conf, final XYDataset xyDataset) { final JFreeChart chart; chart = ChartFactory.createTimeSeriesChart(null, null, null, xyDataset, false, true, true); chart.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR)); chart.setBorderVisible(false);/* www . ja v a 2s. co m*/ final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(conf.color.getColor(MwColor.BACKGROUND_COLOR)); plot.setDomainGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setRangeGridlinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setDomainGridlinesVisible(false); plot.setDomainCrosshairPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final DateAxis axis = (DateAxis) plot.getDomainAxis(); // axis.setDateFormatOverride(new SimpleDateFormat("mm''ss''''SSS")); axis.setAxisLineVisible(false); axis.setTickLabelsVisible(false); axis.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); // force integer display final ValueAxis va = plot.getRangeAxis(); va.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); va.setLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); va.setAxisLinePaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); va.setTickLabelPaint(conf.color.getColor(MwColor.FORGROUND_COLOR)); // va.setRange(-280,280); // va.setFixedAutoRange(560); // va.setLowerBound(-280); // va.setUpperBound(280); // va.setAutoRange(false); va.setRangeWithMargins(-280, 280); final MwChartPanel chartPanel = new MwChartPanel(chart, conf); chartPanel.setMouseWheelEnabled(false); chartPanel.setDomainZoomable(false); chartPanel.setRangeZoomable(false); return chartPanel; }