List of usage examples for org.jfree.chart ChartFactory createLineChart
public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_Stat.java
protected JFreeChart createLegend(CategoryDataset dataset) { // JFreeChart chart = ChartFactory.createAreaChart( JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );/*from w w w . jav a 2 s . c om*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); StatisticalBarRenderer renderer = new StatisticalBarRenderer(); renderer.setErrorIndicatorPaint(Color.black); // renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); plot.setRenderer(renderer); // renderer.setDrawOutlines(true); // renderer.setUseFillPaint(true); // renderer.setFillPaint(Color.white); return chart; }
From source file:gg.view.categoriesbalances.GraphCategoriesBalancesTopComponent.java
/** * Displays the categories/sub-categories' balances by period * @param balances Categories' balances/*from w w w . ja v a 2 s . c om*/ */ private void displayData(Map<Long, Map<SearchCriteria, BigDecimal>> balances) { log.info("Categories' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the categories/sub-categories' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphCategoriesBalancesTopComponent.class, "GraphAccountsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelCategoriesBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for each category/sub-category displayed in the table for (Long categoryId : balances.keySet()) { Category category = Wallet.getInstance().getCategoriesWithId().get(categoryId); assert (category != null); SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>( balances.get(categoryId).keySet()); for (SearchCriteria searchCriteria : sortedSearchCriteria) { if ((!searchCriteria.hasCategoriesFilter() && category.isTopCategory() && !category.getSystemProperty()) || searchCriteria.getCategories().contains(category)) { BigDecimal balance = new BigDecimal(0); if (balances.get(categoryId) != null && balances.get(categoryId).get(searchCriteria) != null) { balance = balances.get(categoryId).get(searchCriteria); } dataset.addValue(balance, category.getName(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelCategoriesBalances.removeAll(); jPanelCategoriesBalances.add(chartPanel, BorderLayout.CENTER); jPanelCategoriesBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:org.deegree.graphics.charts.ChartsBuilder.java
/** * Creates a Line chart// w w w. j a v a 2 s. co m * * @param title * @param keyedValues * key is the category name, value is a series tupels as follows for instance key1 = (arg1,4);(arg2,6) * key2 = (arg1,8); (arg2,11) * @param width * of the output image * @param height * height of the output image * @param is3D * is a 3D Chart * @param legend * for the output chart * @param tooltips * for the output de.latlon.charts * @param orientation * Horiyontal or vertical chart * @param imageType * of the output image * @param horizontalAxisName * Name of the Horizontal Axis * @param verticalAxisName * Name of the vertical Axis * @param chartConfigs * to configure the output chart, or null to use the default ChartConfig * @return BufferedImage representing the generated chart * @throws IncorrectFormatException */ public BufferedImage createLineChart(String title, QueuedMap<String, String> keyedValues, int width, int height, boolean is3D, boolean legend, boolean tooltips, int orientation, String imageType, String horizontalAxisName, String verticalAxisName, ChartConfig chartConfigs) throws IncorrectFormatException { CategoryDataset dataset = convertMapToCategoryDataSet(keyedValues); JFreeChart chart = null; if (is3D) { chart = ChartFactory.createLineChart3D(title, horizontalAxisName, verticalAxisName, dataset, translateToPlotOrientation(orientation), legend, tooltips, false); } else { chart = ChartFactory.createLineChart(title, horizontalAxisName, verticalAxisName, dataset, translateToPlotOrientation(orientation), legend, tooltips, false); } if (chartConfigs == null) { chartConfigs = this.chartConfigs; } return createBufferedImage(configChart(chart, chartConfigs), width, height, imageType); }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_Stat_Raw.java
/** * Creates a chart.//from w w w . ja v a 2 s. c o m * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // create the chart... // create the chart... JFreeChart chart = ChartFactory.createLineChart(chartTitle, // chart title domainLabel, // domain axis label rangeLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation !legendPanelOn, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // customise the renderer... StatisticalBarRenderer renderer = new StatisticalBarRenderer(); renderer.setErrorIndicatorPaint(Color.black); plot.setRenderer(renderer); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:gg.view.accountsbalances.GraphAccountsBalancesTopComponent.java
/** * Displays the accounts' balances by period * @param balances Accounts' balances//w w w .j ava2 s .com */ private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Accounts' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the accounts' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphAccountsBalancesTopComponent.class, "AccountsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelAccountsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for each account displayed in the table for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { Account account = (Account) moneyContainer; SortedSet<SearchCriteria> sortedSearchCriteria = new TreeSet<SearchCriteria>( balances.get(account).keySet()); for (SearchCriteria searchCriteria : sortedSearchCriteria) { if (!searchCriteria.hasAccountsFilter() || searchCriteria.getAccounts().contains(account)) { dataset.addValue(balances.get(moneyContainer).get(searchCriteria), account.toString(), searchCriteria.getPeriod()); } } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelAccountsBalances.removeAll(); jPanelAccountsBalances.add(chartPanel, BorderLayout.CENTER); jPanelAccountsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:org.pentaho.reporting.engine.classic.extensions.legacy.charts.LegacyChartType.java
private JFreeChart createChart(final Expression aExpression) { if (aExpression instanceof BarLineChartExpression) { final CategoryAxis catAxis = new CategoryAxis("Category");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final CategoryPlot plot = new CategoryPlot(createDataset(), catAxis, barsAxis, new BarRenderer()); plot.setRenderer(1, new LineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createDataset()); 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); return new JFreeChart("Bar Line Chart", plot); }//w ww .j av a 2 s . co m if (aExpression instanceof RingChartExpression) { return ChartFactory.createRingChart("Ring Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof AreaChartExpression) { return ChartFactory.createAreaChart("Area Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof BarChartExpression) { return ChartFactory.createBarChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof LineChartExpression) { return ChartFactory.createLineChart("Line Chart", "Category", "Value", createDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof MultiPieChartExpression) { return ChartFactory.createMultiplePieChart("Multi Pie Chart", createDataset(), TableOrder.BY_COLUMN, true, false, false);// NON-NLS } if (aExpression instanceof PieChartExpression) { return ChartFactory.createPieChart("Pie Chart", createPieDataset(), true, false, false);// NON-NLS } if (aExpression instanceof WaterfallChartExpressions) { return ChartFactory.createWaterfallChart("Bar Chart", "Category", "Value", createDataset(), PlotOrientation.HORIZONTAL, true, false, false);// NON-NLS } if (aExpression instanceof BubbleChartExpression) { return ChartFactory.createBubbleChart("Bubble Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ExtendedXYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof ScatterPlotChartExpression) { return ChartFactory.createScatterPlot("Scatter Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYAreaLineChartExpression) { final NumberAxis catAxis = new NumberAxis("Range");// NON-NLS final NumberAxis barsAxis = new NumberAxis("Value");// NON-NLS final NumberAxis linesAxis = new NumberAxis("Value2");// NON-NLS final XYPlot plot = new XYPlot(createXYZDataset(), catAxis, barsAxis, new XYAreaRenderer()); plot.setRenderer(1, new XYLineAndShapeRenderer()); // add lines dataset and axis to plot plot.setDataset(1, createXYZDataset()); 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); return new JFreeChart("XY Area Line Chart", plot);// NON-NLS } if (aExpression instanceof XYAreaChartExpression) { return ChartFactory.createXYAreaChart("XY Area Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYBarChartExpression) { return XYBarChartExpression.createXYBarChart("XY Bar Chart", "X", false, "Y", createIntervalXYDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof XYLineChartExpression) { return ChartFactory.createXYLineChart("XY Line Chart", "X", "Y", createXYZDataset(), PlotOrientation.VERTICAL, true, false, false);// NON-NLS } if (aExpression instanceof RadarChartExpression) { final SpiderWebPlot plot = new SpiderWebPlot(createDataset()); return new JFreeChart("Radar Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } if (aExpression instanceof ThermometerChartExpression) { final DefaultValueDataset dataset = new DefaultValueDataset(new Double(65.0)); final ThermometerPlot plot = new ThermometerPlot(dataset); return new JFreeChart("Thermometer Chart", JFreeChart.DEFAULT_TITLE_FONT, plot, true); } return null; }
From source file:gg.view.movementsbalances.GraphMovementsBalancesTopComponent.java
/** * Displays the accounts' movements balances by period * @param searchFilters Search filter objects (one per period) for which the movements balances are wanted *//*from ww w .j a va 2 s .c o m*/ private void displayData(Map<MoneyContainer, Map<SearchCriteria, BigDecimal>> balances) { log.info("Movements' balances graph computed and displayed"); // Display hourglass cursor Utilities.changeCursorWaitStatus(true); // Create the dataset (that will contain the movements' balances) DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Create an empty chart JFreeChart chart = ChartFactory.createLineChart("", // chart title "", // x axis label NbBundle.getMessage(GraphMovementsBalancesTopComponent.class, "GraphMovementsBalancesTopComponent.Amount"), // y axis label dataset, // data displayed in the chart PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // Chart color chart.setBackgroundPaint(jPanelMovementsBalances.getBackground()); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.WHITE); // Grid lines plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // Set the orientation of the categories on the domain axis (X axis) CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); // Add the series on the chart for (MoneyContainer moneyContainer : balances.keySet()) { if (moneyContainer instanceof Account) { SortedSet<SearchCriteria> sortedSearchFilters = new TreeSet<SearchCriteria>( balances.get(moneyContainer).keySet()); for (SearchCriteria searchCriteria : sortedSearchFilters) { BigDecimal accountBalance = balances.get(moneyContainer).get(searchCriteria); accountBalance = accountBalance.setScale(2, RoundingMode.HALF_EVEN); dataset.addValue(accountBalance, moneyContainer.toString(), searchCriteria.getPeriod()); } } } // Series' shapes LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); for (int i = 0; i < dataset.getRowCount(); i++) { renderer.setSeriesShapesVisible(i, true); renderer.setSeriesShape(i, ShapeUtilities.createDiamond(2F)); } // Set the scale of the chart NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Create the chart panel that contains the chart ChartPanel chartPanel = new ChartPanel(chart); // Display the chart jPanelMovementsBalances.removeAll(); jPanelMovementsBalances.add(chartPanel, BorderLayout.CENTER); jPanelMovementsBalances.updateUI(); // Display normal cursor Utilities.changeCursorWaitStatus(false); }
From source file:simz1.StackedBarChart.java
public void BreadGraph() { DefaultCategoryDataset bidata = new DefaultCategoryDataset(); bidata.setValue(bi1, "sales", d1); bidata.setValue(bi2, "sales", d2); bidata.setValue(bi3, "sales", d3); bidata.setValue(bi4, "sales", d4); bidata.setValue(bi5, "sales", d5); bidata.setValue(bi6, "sales", d6); bidata.setValue(bi7, "sales", d7); JFreeChart chart3 = ChartFactory.createLineChart("Sales of Bread Items last week", "Date", "sales", bidata, PlotOrientation.VERTICAL, false, true, false); CategoryPlot c3 = chart3.getCategoryPlot(); c3.setBackgroundPaint(Color.white); c3.getRenderer().setSeriesPaint(0, Color.GREEN); //c3.setRangeGridlinePaint(Color.green); ChartPanel c3Panel = new ChartPanel(chart3); mhp.chartPanel.removeAll();// w w w.ja v a2s . co m mhp.chartPanel.add(c3Panel); }
From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java
/** * Creates a line chart./*from w w w . ja v a 2s . c om*/ * * @param title * @param categoryAxisLabel * (X-Axis label) * @param valueAxisLabel * (Y-Axis label) * @param dataset * @param includeZero * True when zero shall be included to the axis range. * @return JfreeChart instance. */ public JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, boolean includeZero, boolean drawShapes) { JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, dataset, this.orientation, this.drawLegend, false, false); // set the background color for the chart... chart.setBackgroundPaint(Color.white); chart.setAntiAlias(true); CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.025); domainAxis.setUpperMargin(0.025); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_90); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(includeZero); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); renderer.setSeriesPaint(1, Color.red); renderer.setSeriesPaint(2, Color.green); renderer.setSeriesPaint(3, Color.darkGray); renderer.setSeriesPaint(4, Color.yellow); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseShapesVisible(drawShapes); renderer.setBaseShapesFilled(true); return chart; }
From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java
private static JFreeChart createLineChart(CategoryDataset dataset) { JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 1", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? );//ww w. j ava2 s.com chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setUseOutlinePaint(true); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); return chart; }