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.demo.StatisticalBarChartDemo2.java
/** * Creates a sample chart.// www . j a va 2 s. com * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // 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); renderer.setLegendItemLabelGenerator( new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT)); plot.setRenderer(renderer); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:ec.ui.view.RevisionSaSeriesView.java
/** * Constructs a new view//from w w w . j av a2 s .c o m */ public RevisionSaSeriesView() { setLayout(new BorderLayout()); sRenderer = new XYLineAndShapeRenderer(); sRenderer.setBaseShapesVisible(false); //sRenderer.setSeriesStroke(1, new BasicStroke(0.75f, 1, 1, 1.0f, new float[]{2f, 3f}, 0.0f)); sRenderer.setBasePaint(themeSupport.getLineColor(ColorScheme.KnownColor.RED)); revRenderer = new XYLineAndShapeRenderer(false, true); mainChart = createMainChart(); chartpanel_ = new JChartPanel(ChartFactory.createLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, false, false)); documentpanel_ = ComponentFactory.getDefault().newHtmlView(); JSplitPane splitpane = NbComponents.newJSplitPane(JSplitPane.VERTICAL_SPLIT, chartpanel_, NbComponents.newJScrollPane(documentpanel_)); splitpane.setDividerLocation(0.5); splitpane.setResizeWeight(.5); popup = new ChartPopup(null, false); chartpanel_.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { if (lastIndexSelected != -1) { revRenderer.setSeriesShapesFilled(lastIndexSelected, false); } if (e.getEntity() != null) { if (e.getEntity() instanceof XYItemEntity) { XYItemEntity item = (XYItemEntity) e.getEntity(); if (item.getDataset().equals(mainChart.getXYPlot().getDataset(REV_INDEX))) { int i = item.getSeriesIndex(); revRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6)); revRenderer.setSeriesShapesFilled(i, true); revRenderer.setSeriesPaint(i, themeSupport.getLineColor(ColorScheme.KnownColor.BLUE)); lastIndexSelected = i; showRevisionPopup(e); } } } } @Override public void chartMouseMoved(ChartMouseEvent cme) { } }); chartpanel_.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals(JChartPanel.ZOOM_SELECTION_CHANGED)) { showSelectionPopup((Rectangle2D) evt.getNewValue()); } } }); this.add(splitpane, BorderLayout.CENTER); splitpane.setResizeWeight(0.5); onColorSchemeChange(); }
From source file:com.vectorprint.report.jfree.ChartBuilder.java
private void prepareChart(Dataset data, CHARTTYPE type) throws VectorPrintException { switch (type) { case AREA://from ww w.ja va2s . c om chart = ChartFactory.createAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); case LINE: if (chart == null) { chart = ChartFactory.createLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case LINE3D: if (chart == null) { chart = ChartFactory.createLineChart3D(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case BAR: if (chart == null) { chart = ChartFactory.createBarChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } case BAR3D: if (chart == null) { chart = ChartFactory.createBarChart3D(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } if (data instanceof CategoryDataset) { CategoryDataset cd = (CategoryDataset) data; chart.getCategoryPlot().setDataset(cd); } else { throw new VectorPrintException("you should use CategoryDataset for this chart"); } break; case PIE: chart = ChartFactory.createPieChart(title, null, legend, tooltips, urls); case PIE3D: if (chart == null) { chart = ChartFactory.createPieChart3D(title, null, legend, tooltips, urls); } if (data instanceof PieDataset) { PieDataset pd = (PieDataset) data; PiePlot pp = (PiePlot) chart.getPlot(); pp.setDataset(pd); } else { throw new VectorPrintException("you should use PieDataset for this chart"); } break; case XYLINE: chart = ChartFactory.createXYLineChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); case XYAREA: if (chart == null) { chart = ChartFactory.createXYAreaChart(title, categoryLabel, valueLabel, null, getOrientation(), legend, tooltips, urls); } if (data instanceof XYDataset) { XYDataset xy = (XYDataset) data; chart.getXYPlot().setDataset(xy); } else { throw new VectorPrintException("you should use XYDataset for this chart"); } break; case TIME: chart = ChartFactory.createTimeSeriesChart(title, categoryLabel, valueLabel, null, legend, tooltips, urls); if (data instanceof TimeSeriesCollection) { TimeSeriesCollection xy = (TimeSeriesCollection) data; chart.getXYPlot().setDataset(xy); } else { throw new VectorPrintException("you should use TimeSeriesCollection for this chart"); } break; default: throw new VectorPrintException("unsupported chart"); } chart.setAntiAlias(true); chart.setTextAntiAlias(true); }
From source file:grafici.StatisticheLineChart.java
/** * Creates a sample chart./*ww w.java2 s. c o m*/ * * @param dataset * the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset, Table results, int variabile, int valore) { // create the chart... JFreeChart chart = ChartFactory.createLineChart(titolo, "", // domain axis label results.getColumn(valore).getText().toUpperCase(), // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); // renderer.setDrawShapes(true); renderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); renderer.setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo1.java
/** * Creates a sample chart./* ww w . j a va 2s .com*/ * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { if (isDemo) { chartTitle = "Java Standard Class Library"; domainLabel = "Release"; rangeLabel = "Class Count"; } else chartTitle = "Line 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 ); if (isDemo) { chart.addSubtitle(new TextTitle("Number of Classes By Release")); TextTitle source = new TextTitle( "Source: Java In A Nutshell (4th Edition) " + "by David Flanagan (O'Reilly)"); source.setFont(new Font("SansSerif", Font.PLAIN, 10)); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); } else { chart.clearSubtitles(); } 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()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator()); setCategorySummary(dataset); return chart; }
From source file:br.com.OCTur.view.GraficoController.java
@Override public void initialize(URL url, ResourceBundle rb) { fornecedor = new FornecedorDAO().pegarPorEmpresa(Sessao.pessoa.getEmpresa()); snCategoriasMaisVendida = new SwingNode(); snInteressePorArtesanato = new SwingNode(); snProdutosMaisAntigos = new SwingNode(); spCategoriaMaisVendida.setContent(snCategoriasMaisVendida); spInteressePorArtesanato.setContent(snInteressePorArtesanato); spProdutosMaisAntigos.setContent(snProdutosMaisAntigos); DefaultPieDataset dpdDados = new DefaultPieDataset(); for (CategoriaProduto categoriaProduto : new CategoriaProdutoDAO().pegarTodos()) { List<CompraItem> compraitem = new CompraItemDAO().pegarPorFonecedorCategoria(fornecedor, categoriaProduto);/*w w w. j a v a 2 s.c o m*/ dpdDados.setValue(categoriaProduto.toString(), compraitem.size()); } JFreeChart jFreeChart = ChartFactory.createPieChart3D( ControlTranducao.traduzirPalavra("CATEGORIASMAISVENDIDAS"), dpdDados, false, false, Locale.ROOT); PiePlot3D piePlot3D = (PiePlot3D) jFreeChart.getPlot(); piePlot3D.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}\n{2}")); ChartPanel categoriaMaisVendida = new ChartPanel(jFreeChart); Platform.runLater(() -> { snCategoriasMaisVendida.setContent(categoriaMaisVendida); }); DefaultCategoryDataset dcdDados = new DefaultCategoryDataset(); for (int i = Calendar.getInstance().get(Calendar.YEAR) - 10; i < Calendar.getInstance() .get(Calendar.YEAR); i++) { dcdDados.addValue(new Random().nextDouble() * 100000, "Interesse", String.valueOf(i)); } jFreeChart = ChartFactory.createLineChart( ControlTranducao.traduzirPalavra("interesse") + " " + ControlTranducao.traduzirPalavra("artesanato"), "", "", dcdDados, PlotOrientation.VERTICAL, false, false, false); ChartPanel interesseArtesanato = new ChartPanel(jFreeChart); Platform.runLater(() -> { snInteressePorArtesanato.setContent(interesseArtesanato); }); produto = new ArrayList<>(); for (Produto produto : new ProdutoDAO().pegarPorFornecedor(fornecedor)) { if (new CompraItemDAO().pegarPorProduto(produto).isEmpty()) { List<Item> itens = new ItemDAO().pegarPorProduto(produto); if (!itens.isEmpty()) { Item item = itens.get(0); long quantidade = (new Date().getTime() - item.getDatacadastro().getTime()) / 1000 / 60 / 60 / 24; this.produto.add(new EntidadeGrafico<>(produto, quantidade)); } } } slMeta.setMax(produto.stream().mapToDouble(EntidadeGrafico::getValue).max().orElse(0)); slMeta.valueProperty() .addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> { produtosMaisAntigos(); }); Platform.runLater(() -> { produtosMaisAntigos(); }); }
From source file:Controlador.ControladorLecturas.java
public JInternalFrame graficoTemperatura() { DefaultCategoryDataset defaultCategoryDataset = new DefaultCategoryDataset(); for (Object row : vectorTemperatura()) { int grados = Integer.parseInt(((Vector) row).elementAt(0).toString()); String rowKey = "Sensor 1"; String columnKey = ((Vector) row).elementAt(1).toString(); defaultCategoryDataset.addValue(grados, rowKey, columnKey); }/*from w w w.ja v a2 s. c o m*/ JFreeChart jFreeChart = ChartFactory.createLineChart(null, "Hora", "Grados", defaultCategoryDataset, PlotOrientation.VERTICAL, true, true, true); ChartPanel chartPanel = new ChartPanel(jFreeChart); JInternalFrame jInternalFrame = new JInternalFrame("Grafico de Temperatura Ambiental", true, true, true, true); jInternalFrame.add(chartPanel, BorderLayout.CENTER); jInternalFrame.pack(); return jInternalFrame; }
From source file:edu.ucla.stat.SOCR.chart.demo.StatisticalLineChartDemo2.java
/** * Creates a sample chart.//from w w w. ja va 2s . c om * * @param dataset a dataset. * * @return The chart. */ protected JFreeChart createChart(CategoryDataset dataset) { // 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 ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setUpperMargin(0.0); domainAxis.setLowerMargin(0.0); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); // customise the renderer... StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(true, false); renderer.setLegendItemLabelGenerator( new SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT)); plot.setRenderer(renderer); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:com.sun.japex.report.ChartGenerator.java
/** * Create a chart for a single mean across all drivers. *//*from w ww . jav a 2 s . c o m*/ public JFreeChart createTrendChart(MeanMode mean) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); final int size = _reports.size(); for (int i = 0; i < size; i++) { TestSuiteReport report = _reports.get(i); SimpleDateFormat formatter = _dateFormatter; // If previous or next are on the same day, include time if (i > 0 && onSameDate(report, _reports.get(i - 1))) { formatter = _dateTimeFormatter; } if (i + 1 < size && onSameDate(report, _reports.get(i + 1))) { formatter = _dateTimeFormatter; } List<TestSuiteReport.Driver> drivers = report.getDrivers(); for (TestSuiteReport.Driver driver : drivers) { double value = driver.getResult(mean); if (!Double.isNaN(value)) { dataset.addValue(driver.getResult(MeanMode.ARITHMETIC), driver.getName(), formatter.format(report.getDate().getTime())); } } } JFreeChart chart = ChartFactory.createLineChart(mean.toString(), "", "", dataset, PlotOrientation.VERTICAL, true, true, false); configureLineChart(chart); chart.setAntiAlias(true); return chart; }
From source file:hudson.model.LoadStatistics.java
/** * Creates a trend chart.// w w w. j a v a 2 s . co m */ public JFreeChart createChart(CategoryDataset ds) { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused null, // range axis label ds, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(3)); configureRenderer(renderer); final CategoryAxis domainAxis = new NoOverlapCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // crop extra space around the graph plot.setInsets(new RectangleInsets(0, 0, 0, 5.0)); return chart; }