public static void setTimeSeriesBarRender(Plot plot, boolean isShowDataLabels) { XYPlot xyplot = (XYPlot) plot; xyplot.setNoDataMessage(NO_DATA_MSG); XYBarRenderer xyRenderer = new XYBarRenderer(0.1D); xyRenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); if (isShowDataLabels) { xyRenderer.setBaseItemLabelsVisible(true); xyRenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); } StandardXYToolTipGenerator xyTooltipGenerator = new StandardXYToolTipGenerator("{1}:{2}", new SimpleDateFormat("yyyy-MM-dd"), new DecimalFormat("0")); xyRenderer.setBaseToolTipGenerator(xyTooltipGenerator); setXY_XAixs(xyplot); setXY_YAixs(xyplot); }
private void plotSeperate(XYDataset dataset, String p) { NumberAxis rangeAxis1 = new NumberAxis(p); rangeAxis1.setAutoRangeIncludesZero(false); // override default rangeAxis1.setLowerMargin(0.40); // to leave room for volume bars DecimalFormat format = new DecimalFormat("0"); rangeAxis1.setNumberFormatOverride(format); final ValueAxis timeAxis = new DateAxis("Date"); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); XYPlot plot = new XYPlot(dataset, timeAxis, rangeAxis1, null); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00#") ) ); plot.setRenderer(0, renderer1); final CombinedDomainXYPlot cplot1 = (CombinedDomainXYPlot)this.candlestickChart.getPlot(); if (plot != null) cplot1.add(plot, 1); // weight is 1. }
/** * Creates a wind plot with default settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the x-axis (<code>null</code> permitted). * @param yAxisLabel a label for the y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag that controls whether or not a legend is created. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A wind plot. * */ public static JFreeChart createWindPlot(String title, String xAxisLabel, String yAxisLabel, WindDataset dataset, boolean legend, boolean tooltips, boolean urls) { ValueAxis xAxis = new DateAxis(xAxisLabel); ValueAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setRange(-12.0, 12.0); WindItemRenderer renderer = new WindItemRenderer(); if (tooltips) { renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
/** * Creates a line chart (based on an {@link XYDataset}) with default * settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the plot orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return The chart. */ public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { ParamChecks.nullNotPermitted(orientation, "orientation"); NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a wind plot with default settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the x-axis (<code>null</code> permitted). * @param yAxisLabel a label for the y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag that controls whether or not a legend is created. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A wind plot. * */ public static JFreeChart createWindPlot(String title, String xAxisLabel, String yAxisLabel, WindDataset dataset, boolean legend, boolean tooltips, boolean urls) { ValueAxis xAxis = new DateAxis(xAxisLabel); ValueAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setRange(-12.0, 12.0); WindItemRenderer renderer = new WindItemRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a line chart (based on an {@link XYDataset}) with default * settings. * * @param title the chart title ({@code null} permitted). * @param xAxisLabel a label for the X-axis ({@code null} permitted). * @param yAxisLabel a label for the Y-axis ({@code null} permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param orientation the plot orientation (horizontal or vertical) * ({@code null} NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return The chart. */ public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { Args.nullNotPermitted(orientation, "orientation"); NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(orientation); if (tooltips) { renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a wind plot with default settings. * * @param title the chart title ({@code null} permitted). * @param xAxisLabel a label for the x-axis ({@code null} permitted). * @param yAxisLabel a label for the y-axis ({@code null} permitted). * @param dataset the dataset for the chart ({@code null} permitted). * @param legend a flag that controls whether or not a legend is created. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A wind plot. * */ public static JFreeChart createWindPlot(String title, String xAxisLabel, String yAxisLabel, WindDataset dataset, boolean legend, boolean tooltips, boolean urls) { ValueAxis xAxis = new DateAxis(xAxisLabel); ValueAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setRange(-12.0, 12.0); WindItemRenderer renderer = new WindItemRenderer(); if (tooltips) { renderer.setDefaultToolTipGenerator(new StandardXYToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYURLGenerator()); } XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a sample chart. * * @param dataset a dataset for the chart. * @return A sample chart. */ private static JFreeChart createChart( XYDataset dataset ) { JFreeChart chart = ChartFactory.createXYLineChart( "XYLineAndShapeRenderer Demo 1", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false ); XYPlot plot = (XYPlot)chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible( 0, true ); renderer.setSeriesShapesVisible( 0, false ); renderer.setSeriesLinesVisible( 1, true ); renderer.setSeriesShapesVisible( 1, false ); renderer.setToolTipGenerator( new StandardXYToolTipGenerator() ); renderer.setDefaultEntityRadius( 6 ); plot.setRenderer( renderer ); return chart; }
/** * Creates a sample chart. * * @param dataset a dataset for the chart. * * @return A sample chart. */ protected JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createXYLineChart( chartTitle, domainLabel, rangeLabel, dataset, PlotOrientation.VERTICAL, !legendPanelOn, true, false ); XYPlot plot = (XYPlot) chart.getPlot(); XYStepRenderer renderer = new XYStepRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setDefaultEntityRadius(6); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); plot.setRenderer(renderer); setXSummary(dataset); return chart; }
/** * Creates a sample chart. * * @param dataset the dataset for the chart. * * @return a sample chart. */ protected JFreeChart createChart(TableXYDataset dataset) { JFreeChart chart = ChartFactory.createStackedXYAreaChart( chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // the plot orientation !legendPanelOn, // legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(0, renderer); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); setXSummary(dataset); return chart; }
/** * Creates a chart. * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(TableXYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createStackedXYAreaChart( chartTitle, // chart title domainLabel, // x axis label rangeLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, !legendPanelOn, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(0, renderer); return chart; }
protected JFreeChart createLegend(TableXYDataset dataset) { // JFreeChart chart = ChartFactory.createAreaChart( JFreeChart chart = ChartFactory.createStackedXYAreaChart( chartTitle, // chart title domainLabel, // x axis label rangeLabel, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... XYPlot plot = (XYPlot) chart.getPlot(); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(0, renderer); renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator()); return chart; }
private JFreeChart createXYBarChart(ReportChart reportChart, ChartValue[] values, boolean displayInline) { XYDataset dataset = createXYDataset(values); NumberAxis xAxis = new NumberAxis(reportChart.getXAxisLabel()); NumberAxis yAxis = new NumberAxis(reportChart.getYAxisLabel()); XYBarRenderer renderer = new XYBarRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) { plot.setOrientation(PlotOrientation.HORIZONTAL); } return new JFreeChart(reportChart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart.isShowLegend()); }
private JFreeChart createTimeBarChart(ReportChart reportChart, ChartValue[] values, boolean displayInline) { JFreeChart chart = null; XYDataset dataset = createTimeDataset(values); ValueAxis timeAxis = new DateAxis(reportChart.getXAxisLabel()); NumberAxis valueAxis = new NumberAxis(reportChart.getYAxisLabel()); XYItemRenderer renderer = new XYBarRenderer(); renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) { plot.setOrientation(PlotOrientation.HORIZONTAL); } chart = new JFreeChart(reportChart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart.isShowLegend()); return chart; }
private JFreeChart createStackedTimeBarChart(ReportChart reportChart, ChartValue[] values, boolean displayInline) { XYDataset dataset = createTimeDataset(values); ValueAxis timeAxis = new DateAxis(reportChart.getXAxisLabel()); NumberAxis valueAxis = new NumberAxis(reportChart.getYAxisLabel()); XYItemRenderer renderer = new StackedXYBarRenderer(); renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) { plot.setOrientation(PlotOrientation.HORIZONTAL); } return new JFreeChart(reportChart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart.isShowLegend()); }
private JFreeChart createStackedXYBarChart(ReportChart reportChart, ChartValue[] values, boolean displayInline) { XYDataset dataset = createXYDataset(values); NumberAxis xAxis = new NumberAxis(reportChart.getXAxisLabel()); NumberAxis yAxis = new NumberAxis(reportChart.getYAxisLabel()); StackedXYBarRenderer renderer = new StackedXYBarRenderer(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); if (reportChart.getPlotOrientation() == ReportChart.HORIZONTAL) { plot.setOrientation(PlotOrientation.HORIZONTAL); } return new JFreeChart(reportChart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, reportChart.isShowLegend()); }
/** * Creates a scatter plot with default settings. The chart object * returned by this method uses an {@link XYPlot} instance as the plot, * with a {@link NumberAxis} for the domain axis, a {@link NumberAxis} * as the range axis, and an {@link XYLineAndShapeRenderer} as the * renderer. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A scatter plot. */ public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, boolean legend) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates an area chart using an {@link XYDataset}. * <P> * The chart object returned by this method uses an {@link XYPlot} instance * as the plot, with a {@link NumberAxis} for the domain axis, a * {@link NumberAxis} as the range axis, and a {@link XYAreaRenderer} as * the renderer. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return An XY area chart. */ public static JFreeChart createXYAreaChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, boolean legend) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setForegroundAlpha(0.5f); XYAreaRenderer renderer = new XYAreaRenderer(XYAreaRenderer.AREA); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a stacked XY area plot. The chart object returned by this * method uses an {@link XYPlot} instance as the plot, with a * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and a {@link StackedXYAreaRenderer2} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A stacked XY area chart. */ public static JFreeChart createStackedXYAreaChart(String title, String xAxisLabel, String yAxisLabel, TableXYDataset dataset, boolean legend) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); xAxis.setLowerMargin(0.0); xAxis.setUpperMargin(0.0); NumberAxis yAxis = new NumberAxis(yAxisLabel); StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setOutline(true); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setRangeAxis(yAxis); // forces recalculation of the axis range JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a line chart (based on an {@link XYDataset}) with default * settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return The chart. */ public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, boolean legend) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a stepped XY plot with default settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A chart. */ public static JFreeChart createXYStepChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, boolean legend) { DateAxis xAxis = new DateAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYItemRenderer renderer = new XYStepRenderer(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setRenderer(renderer); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a filled stepped XY plot with default settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A chart. */ public static JFreeChart createXYStepAreaChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, boolean legend) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYStepAreaRenderer( XYStepAreaRenderer.AREA_AND_SHAPES); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setRenderer(renderer); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates and returns a time series chart. A time series chart is an * {@link XYPlot} with a {@link DateAxis} for the x-axis and a * {@link NumberAxis} for the y-axis. The default renderer is an * {@link XYLineAndShapeRenderer}. A convenient dataset to use with this * chart is a {@link TimeSeriesCollection}. * * @param title the chart title (<code>null</code> permitted). * @param timeAxisLabel a label for the time axis (<code>null</code> * permitted). * @param valueAxisLabel a label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A time series chart. */ public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend) { ValueAxis timeAxis = new DateAxis(timeAxisLabel); timeAxis.setLowerMargin(0.02); // reduce the default margins timeAxis.setUpperMargin(0.02); NumberAxis valueAxis = new NumberAxis(valueAxisLabel); valueAxis.setAutoRangeIncludesZero(false); // override default XYPlot plot = new XYPlot(dataset, timeAxis, valueAxis, null); XYToolTipGenerator toolTipGenerator = null; toolTipGenerator = StandardXYToolTipGenerator.getTimeSeriesInstance(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setBaseToolTipGenerator(toolTipGenerator); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a histogram chart. This chart is constructed with an * {@link XYPlot} using an {@link XYBarRenderer}. The domain and range * axes are {@link NumberAxis} instances. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel the x axis label (<code>null</code> permitted). * @param yAxisLabel the y axis label (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param legend create a legend? * * @return The chart. */ public static JFreeChart createHistogram(String title, String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset, boolean legend) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); ValueAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYBarRenderer(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Creates a wind plot with default settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the x-axis (<code>null</code> permitted). * @param yAxisLabel a label for the y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag that controls whether or not a legend is created. * * @return A wind plot. */ public static JFreeChart createWindPlot(String title, String xAxisLabel, String yAxisLabel, WindDataset dataset, boolean legend) { ValueAxis xAxis = new DateAxis(xAxisLabel); ValueAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setRange(-12.0, 12.0); WindItemRenderer renderer = new WindItemRenderer(); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
public static JFreeChart createFunctionChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, boolean legend, boolean tooltips) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); FunctionPlot plot = new FunctionPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
private List<XYItemRenderer> createStrictRenderers(String id, int n) { List<XYItemRenderer> renderers = new ArrayList<>(); List<Color> colorList = colorLists.containsKey(id) ? colorLists.get(id) : ChartUtils.createColorList(n); List<NamedShape> shapeList = shapeLists.containsKey(id) ? shapeLists.get(id) : ChartUtils.createShapeList(n); for (int i = 0; i < n; i++) { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(drawLines, true); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setSeriesPaint(0, colorList.get(i)); renderer.setSeriesShape(0, shapeList.get(i).getShape()); renderers.add(renderer); } return renderers; }