List of usage examples for org.jfree.chart JFreeChart DEFAULT_TITLE_FONT
Font DEFAULT_TITLE_FONT
To view the source code for org.jfree.chart JFreeChart DEFAULT_TITLE_FONT.
Click Source Link
From source file:KIDLYFactory.java
/** * Creates a stacked area chart with default settings. The chart object * returned by this method uses a {@link CategoryPlot} instance as the * plot, with a {@link CategoryAxis} for the domain axis, a * {@link NumberAxis} as the range axis, and a {@link StackedAreaRenderer} * as the renderer.//from w w w . j a va2s .co m * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value 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 A stacked area chart. */ public static JFreeChart createStackedAreaChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); categoryAxis.setCategoryMargin(0.0); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); StackedAreaRenderer renderer = new StackedAreaRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a line chart with default settings. The chart object returned * by this method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and a {@link LineAndShapeRenderer} as the renderer. * //from w w w .j a v a2 s .c o m * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the chart 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 A line chart. */ public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:jhplot.HChart.java
/** * Update the chart/*from ww w.j a v a 2 s .c o m*/ * * @param N1 * location in X * @param N2 * location in Y */ public void update(int N1, int N2) { if (cdatPie[N1][N2] != null || cdatPie3D[N1][N2] != null || cdatBar[N1][N2] != null || cdatBar3D[N1][N2] != null || cdatLine[N1][N2] != null || cdatArea[N1][N2] != null || cdatPolar[N1][N2] != null) { if (cdatPie[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPieChart(title[N1][N2], (PieDataset) cdatPie[N1][N2], true, true, true); } else if (cdatPie3D[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPieChart3D(title[N1][N2], (PieDataset) cdatPie3D[N1][N2], true, true, true); PiePlot3D pieplot3d = (PiePlot3D) chart[N1][N2].getPlot(); // pieplot3d.setStartAngle(290D); // pieplot3d.setDirection(Rotation.CLOCKWISE); // pieplot3d.setForegroundAlpha(0.5F); pieplot3d.setBackgroundPaint(DEFAULT_BG_COLOR); } else if (cdatBar[N1][N2] != null) { chart[N1][N2] = ChartFactory.createBarChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatBar[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); } else if (cdatBar3D[N1][N2] != null) { chart[N1][N2] = ChartFactory.createBarChart3D(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatBar3D[N1][N2], PlotOrientation.VERTICAL, true, true, true); } else if (cdatLine[N1][N2] != null) { chart[N1][N2] = ChartFactory.createLineChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatLine[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); lineplot.setOutlineStroke(new BasicStroke(axisPenwidth)); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); LineAndShapeRenderer renderer = (LineAndShapeRenderer) lineplot.getRenderer(); renderer.setBaseStroke(new BasicStroke(linestroke)); for (int m = 0; m < cdatLine[N1][N2].getColumnCount() + 1; m++) renderer.setSeriesStroke(m, new BasicStroke(linestroke)); } else if (cdatPolar[N1][N2] != null) { chart[N1][N2] = ChartFactory.createPolarChart(title[N1][N2], (XYSeriesCollection) cdatPolar[N1][N2], true, true, true); PolarPlot lineplot = (PolarPlot) chart[N1][N2].getPlot(); ValueAxis yy = lineplot.getAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); } else if (cdatArea[N1][N2] != null) { chart[N1][N2] = ChartFactory.createAreaChart(title[N1][N2], titleX[N1][N2], titleY[N1][N2], (CategoryDataset) cdatArea[N1][N2], PlotOrientation.VERTICAL, true, true, true); CategoryPlot lineplot = (CategoryPlot) chart[N1][N2].getPlot(); CategoryAxis yy = lineplot.getDomainAxis(); yy.setTickLabelPaint(tickColor); yy.setTickLabelFont(tickFont); yy.setLabelPaint(labelColor); yy.setLabelFont(labelFont); yy.setAxisLineStroke(new BasicStroke(axisPenwidth)); yy.setAxisLinePaint(Color.black); ValueAxis xx = lineplot.getRangeAxis(); xx.setTickLabelPaint(tickColor); xx.setTickLabelFont(tickFont); xx.setLabelPaint(labelColor); xx.setLabelFont(labelFont); xx.setAxisLineStroke(new BasicStroke(axisPenwidth)); xx.setAxisLinePaint(Color.black); } chart[N1][N2].setAntiAlias(antiAlias); chart[N1][N2].setBorderPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBorderVisible(false); cp[N1][N2].setChart(chart[N1][N2]); return; } for (int i = 0; i < indexdat[N1][N2]; i++) { if (type[N1][N2].get(i) == "array") xyplot[N1][N2].setRenderer(i, (StandardXYItemRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "f") xyplot[N1][N2].setRenderer(i, (XYLineAndShapeRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "h") xyplot[N1][N2].setRenderer(i, (XYBarRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "p") xyplot[N1][N2].setRenderer(i, (XYLineAndShapeRenderer) (rdat[N1][N2].get(i))); else if (type[N1][N2].get(i) == "pe") xyplot[N1][N2].setRenderer(i, (XYErrorRenderer) (rdat[N1][N2].get(i))); // System.out.println(i); } chart[N1][N2] = new JFreeChart(title[N1][N2], JFreeChart.DEFAULT_TITLE_FONT, xyplot[N1][N2], true); chart[N1][N2].setAntiAlias(antiAlias); chart[N1][N2].setBorderPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBackgroundPaint(DEFAULT_BG_COLOR); chart[N1][N2].setBorderVisible(false); cp[N1][N2].setChart(chart[N1][N2]); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample vertically combined chart. * * @return a sample vertically combined chart. *//*w w w . ja v a 2s . com*/ public JFreeChart createVerticallyCombinedChart() { // create a default chart based on some sample data... final String title = this.resources.getString("combined.vertical.title"); final String subtitleStr = this.resources.getString("combined.vertical.subtitle"); final String domain = this.resources.getString("combined.vertical.domain"); final String[] ranges = this.resources.getStringArray("combined.vertical.ranges"); final TimeSeriesCollection dataset0 = new TimeSeriesCollection(); final TimeSeries eur = DemoDatasetFactory.createEURTimeSeries(); dataset0.addSeries(eur); final TimeSeriesCollection dataset1 = new TimeSeriesCollection(); final TimeSeries jpy = DemoDatasetFactory.createJPYTimeSeries(); final TimeSeries mav = MovingAverage.createMovingAverage(jpy, "JPY/GBP (30 Day MA)", 30, 30); dataset1.addSeries(jpy); dataset1.addSeries(mav); final XYDataset dataset2 = DemoDatasetFactory.createHighLowDataset(); final TimeSeriesCollection dataset3 = new TimeSeriesCollection(); dataset3.addSeries(eur); // make one shared horizontal axis final ValueAxis timeAxis = new DateAxis(domain); // make a vertically CombinedPlot that will contain the sub-plots final CombinedDomainXYPlot multiPlot = new CombinedDomainXYPlot(timeAxis); final int[] weight = { 1, 1, 1, 1 }; // control vertical space allocated to each sub-plot // add subplot1... final XYPlot subplot1 = new XYPlot(dataset0, null, new NumberAxis(ranges[0]), new StandardXYItemRenderer()); final NumberAxis range1 = (NumberAxis) subplot1.getRangeAxis(); range1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); range1.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); range1.setAutoRangeIncludesZero(false); multiPlot.add(subplot1, weight[0]); // add subplot2... final XYPlot subplot2 = new XYPlot(dataset1, null, new NumberAxis(ranges[1]), new StandardXYItemRenderer()); final NumberAxis range2 = (NumberAxis) subplot2.getRangeAxis(); range2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); range2.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); range2.setAutoRangeIncludesZero(false); multiPlot.add(subplot2, weight[1]); // add subplot3... final XYPlot subplot3 = new XYPlot(dataset2, null, new NumberAxis(ranges[2]), null); final XYItemRenderer renderer3 = new HighLowRenderer(); subplot3.setRenderer(renderer3); final NumberAxis range3 = (NumberAxis) subplot3.getRangeAxis(); range3.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); range3.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); range3.setAutoRangeIncludesZero(false); multiPlot.add(subplot3, weight[2]); // add subplot4... final XYPlot subplot4 = new XYPlot(dataset3, null, new NumberAxis(ranges[3]), null); final XYItemRenderer renderer4 = new XYBarRenderer(); subplot4.setRenderer(renderer4); final NumberAxis range4 = (NumberAxis) subplot4.getRangeAxis(); range4.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 7)); range4.setLabelFont(new Font("SansSerif", Font.PLAIN, 8)); range4.setAutoRangeIncludesZero(false); multiPlot.add(subplot4, weight[3]); // now make the top level JFreeChart that contains the CombinedPlot final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, multiPlot, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); return chart; }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createBarLineChart(final BarLineChartDefinition chartDefinition) { // TODO Make the following accessible from the chartDefinition String categoryAxisLabel = null; String valueAxisLabel = null; String secondValueAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); PlotOrientation orientation = chartDefinition.getOrientation(); // split BarLineChartDefinition in two Definitions CategoryDatasetChartDefinition barsDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); CategoryDatasetChartDefinition linesDataset = new CategoryDatasetChartDefinition( chartDefinition.getSession(), chartDefinition.getChartAttributes()); /*//from ww w. ja v a2 s .c o m * try{ barsDataset = (CategoryDatasetChartDefinition)chartDefinition.clone(); linesDataset = * (CategoryDatasetChartDefinition)chartDefinition.clone(); }catch(Exception e){} */ // get column and row count of the data set int iColumnCount = chartDefinition.getColumnCount(); int iRowCount = chartDefinition.getRowCount(); if (iRowCount <= 0) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_NO_DATA_AVAILABLE")); //$NON-NLS-1$ } /* * Copy data to the two new data sets */ // Loop through columns for (int r = 0; r < iRowCount; r++) { // check if measure should be include in bar or line dataset String strMeasureName = (String) chartDefinition.getRowKey(r); boolean bIsBarColumn = JFreeChartEngine.isBarColumn(chartDefinition.getBarColumns(), strMeasureName); boolean bIsLineColumn = JFreeChartEngine.isLineColumn(chartDefinition.getLineColumns(), strMeasureName); // getting all values for (int c = 0; c < iColumnCount; c++) { Comparable compColumnName = chartDefinition.getColumnKey(c); Number nValue = chartDefinition.getValue(strMeasureName, compColumnName); if (bIsBarColumn) { barsDataset.addValue(nValue, strMeasureName, compColumnName); } if (bIsLineColumn) { linesDataset.addValue(nValue, strMeasureName, compColumnName); } } } if ((iRowCount > 0) && (barsDataset.getRowCount() <= 0) && (linesDataset.getRowCount() <= 0)) { chartDefinition.setNoDataMessage(Messages.getInstance().getString("CHART.USER_INCORRECT_DATA_FORMAT")); //$NON-NLS-1$ } // Create Axis Objects CategoryAxis catAxis = new CategoryAxis(categoryAxisLabel); NumberAxis barsAxis = new NumberAxis(valueAxisLabel); NumberAxis linesAxis = new NumberAxis(secondValueAxisLabel); // set title and font for lines Axis linesDataset.setRangeTitle(chartDefinition.getLinesRangeTitle()); linesDataset.setRangeTitleFont(chartDefinition.getLinesRangeTitleFont()); if (chartDefinition.getLinesRangeTickFormat() != null) { linesAxis.setNumberFormatOverride(chartDefinition.getLinesRangeTickFormat()); } // create renderer BarRenderer barRenderer = null; LineAndShapeRenderer lineRenderer = null; // Determine the type of renderer to use if (chartDefinition.isStacked() || chartDefinition.isThreeD()) { if (chartDefinition.isStacked() && chartDefinition.isThreeD()) { barRenderer = new StackedBarRenderer3D(); lineRenderer = new LineRenderer3D(); } else if (chartDefinition.isStacked()) { barRenderer = new StackedBarRenderer(); lineRenderer = new LineAndShapeRenderer(); } else { barRenderer = new BarRenderer3D(); lineRenderer = new LineRenderer3D(); } } else { barRenderer = new BarRenderer(); lineRenderer = new LineAndShapeRenderer(); } if (orientation == PlotOrientation.HORIZONTAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE3, TextAnchor.CENTER_LEFT); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE9, TextAnchor.CENTER_RIGHT); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } else if (orientation == PlotOrientation.VERTICAL) { ItemLabelPosition position1 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER); barRenderer.setPositiveItemLabelPosition(position1); lineRenderer.setPositiveItemLabelPosition(position1); ItemLabelPosition position2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE6, TextAnchor.TOP_CENTER); barRenderer.setNegativeItemLabelPosition(position2); lineRenderer.setNegativeItemLabelPosition(position2); } if (tooltips) { barRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); lineRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { barRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); lineRenderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } if (chartDefinition.getMaxBarWidth() != null) { barRenderer.setMaximumBarWidth(chartDefinition.getMaxBarWidth().doubleValue()); } // setting some line attributes lineRenderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth())); lineRenderer.setShapesVisible(chartDefinition.isMarkersVisible()); lineRenderer.setBaseShapesFilled(chartDefinition.isMarkersVisible()); /* * Create plot and make necessary adjustments for overlaid chart */ // create the plot with bar chart CategoryPlot plot = new CategoryPlot(barsDataset, catAxis, barsAxis, barRenderer); // add line renderer plot.setRenderer(1, lineRenderer); // add lines dataset, renderer and axis to plot plot.setDataset(1, linesDataset); plot.setRangeAxis(1, linesAxis); // map lines to second axis plot.mapDatasetToRangeAxis(1, 1); // set rendering order plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // standard settings for plots JFreeChartEngine.updatePlot(plot, barsDataset); // additional settings for second axis ValueAxis secondValueAxis = plot.getRangeAxis(1); if (secondValueAxis != null) { if (chartDefinition.getLinesRangeTitle() != null) { secondValueAxis.setLabel(chartDefinition.getLinesRangeTitle()); } if (chartDefinition.getLinesRangeTitleFont() != null) { secondValueAxis.setLabelFont(chartDefinition.getLinesRangeTitleFont()); } if (chartDefinition.getLinesRangeTickFont() != null) { secondValueAxis.setTickLabelFont(chartDefinition.getLinesRangeTickFont()); } if (chartDefinition.getLinesRangeMinimum() != ValueAxis.DEFAULT_LOWER_BOUND) { secondValueAxis.setLowerBound(chartDefinition.getLinesRangeMinimum()); } if (chartDefinition.getLinesRangeMaximum() != ValueAxis.DEFAULT_UPPER_BOUND) { secondValueAxis.setUpperBound(chartDefinition.getLinesRangeMaximum()); } } JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:KIDLYFactory.java
/** * Creates a line chart with default settings. The chart object returned * by this method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the * range axis, and a {@link LineAndShapeRenderer} as the renderer. * * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted)./*from w w w . j a v a 2 s. co m*/ * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the chart 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 A line chart. */ public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
From source file:edu.dlnu.liuwenpeng.ChartFactory.ChartFactory.java
/** * Creates a line chart with default settings. The chart object returned by * this method uses a {@link CategoryPlot} instance as the plot, with a * {@link CategoryAxis3D} for the domain axis, a {@link NumberAxis3D} as * the range axis, and a {@link LineRenderer3D} as the renderer. * /*from ww w. j a v a 2 s.co m*/ * @param title the chart title (<code>null</code> permitted). * @param categoryAxisLabel the label for the category axis * (<code>null</code> permitted). * @param valueAxisLabel the label for the value axis (<code>null</code> * permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the chart 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 A line chart. */ public static JFreeChart createLineChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } CategoryAxis categoryAxis = new CategoryAxis3D(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis3D(valueAxisLabel); LineRenderer3D renderer = new LineRenderer3D(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java
private static JFreeChart createAreaChart(final CategoryDatasetChartDefinition chartDefinition) { // TODO Make the following accessible from the chartDefinition String categoryAxisLabel = null; String valueAxisLabel = null; boolean tooltips = true; boolean urls = true; // ----------------------------------------------------------- String title = chartDefinition.getTitle(); boolean legend = chartDefinition.isLegendIncluded(); CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); AreaRenderer renderer = chartDefinition.isStacked() ? new StackedAreaRenderer() : new AreaRenderer(); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); }//from w w w.ja v a 2 s. c o m if (urls) { renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator()); } CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer); JFreeChartEngine.updatePlot(plot, chartDefinition); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
From source file:org.sakaiproject.sitestats.impl.ServerWideReportManagerImpl.java
private byte[] createDailyLoginChart(int width, int height) { IntervalXYDataset dataset1 = getDailyLoginsDataSet(); IntervalXYDataset dataset2 = getDailySiteUserDataSet(); if ((dataset1 == null) || (dataset2 == null)) { return generateNoDataChart(width, height); }/*from ww w. jav a2 s.c om*/ // create plot ... XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setSeriesPaint(0, Color.RED); renderer1.setSeriesPaint(1, Color.BLUE); renderer1.setSeriesPaint(2, Color.RED); renderer1.setSeriesPaint(3, Color.BLUE); renderer1.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); BasicStroke dashLineStroke = new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { 4 }, 0); renderer1.setSeriesStroke(2, dashLineStroke); renderer1.setSeriesStroke(3, dashLineStroke); DateAxis domainAxis = new DateAxis(""); domainAxis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 7, new SimpleDateFormat("yyyy-MM-dd"))); domainAxis.setTickMarkPosition(DateTickMarkPosition.START); domainAxis.setVerticalTickLabels(true); domainAxis.setLowerMargin(0.01); domainAxis.setUpperMargin(0.01); NumberAxis rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot1 = new XYPlot(dataset1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer2.setSeriesPaint(0, Color.GREEN); renderer2.setSeriesPaint(1, Color.BLACK); renderer2.setSeriesPaint(2, Color.CYAN); rangeAxis = new NumberAxis("count"); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYPlot plot2 = new XYPlot(dataset2, null, rangeAxis, renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, cplot, false); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); // set background chart.setBackgroundPaint(parseColor(statsManager.getChartBackgroundColor())); // set chart border chart.setPadding(new RectangleInsets(10, 5, 5, 5)); chart.setBorderVisible(true); chart.setBorderPaint(parseColor("#cccccc")); // set anti alias chart.setAntiAlias(true); BufferedImage img = chart.createBufferedImage(width, height); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try { ImageIO.write(img, "png", out); } catch (IOException e) { log.warn("Error occurred while generating SiteStats chart image data", e); } return out.toByteArray(); }
From source file:qmul.align.AlignmentTester.java
/** * Plot a turn vs score chart with arbitrary subplots * //from w w w .jav a 2s .c om * @param scores1 * @param title */ private void plotScores(String title, List<Double>... scores) { ApplicationFrame af = new ApplicationFrame(title); final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis()); plot.setGap(10.0); for (int i = 0; i < scores.length; i++) { final XYSeries series = new XYSeries("Coherence scores " + i); for (int x = 0; x < scores[i].size(); x++) { series.add(x, scores[i].get(x)); } XYSeriesCollection data = new XYSeriesCollection(series); XYPlot subplot = new XYPlot(data, null, new NumberAxis(), new StandardXYItemRenderer()); subplot.setRangeAxisLocation(i == 0 ? AxisLocation.TOP_OR_LEFT : AxisLocation.BOTTOM_OR_LEFT); plot.add(subplot, 1); } plot.setOrientation(PlotOrientation.VERTICAL); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(1000, 500)); af.setContentPane(chartPanel); af.pack(); RefineryUtilities.centerFrameOnScreen(af); af.setVisible(true); }