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_Raw.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 );// w w w . ja v a2 s . co m // 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 SOCRCategoryCellLabelGenerator(dataset, values_storage, SERIES_COUNT, CATEGORY_COUNT)); plot.setRenderer(renderer); return chart; }
From source file:simz1.StackedBarChart.java
public void DrinksGraph() { DefaultCategoryDataset drdata = new DefaultCategoryDataset(); drdata.setValue(dr1, "sales", d1); drdata.setValue(dr2, "sales", d2); drdata.setValue(dr3, "sales", d3); drdata.setValue(dr4, "sales", d4); drdata.setValue(dr5, "sales", d5); drdata.setValue(dr6, "sales", d6); drdata.setValue(dr7, "sales", d7); JFreeChart chart4 = ChartFactory.createLineChart("Sales of Drinks last week", "Date", "sales", drdata, PlotOrientation.VERTICAL, false, true, false); CategoryPlot c4 = chart4.getCategoryPlot(); c4.setBackgroundPaint(Color.white); c4.getRenderer().setSeriesPaint(0, Color.YELLOW); //c4.setRangeGridlinePaint(Color.yellow); ChartPanel c4Panel = new ChartPanel(chart4); mhp.chartPanel.removeAll();//from w w w . j a va 2s . com mhp.chartPanel.add(c4Panel); }
From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java
/** * This method generates an image of a chart of the evolution of the total * amount of money a properties book selection for a year in a monthly bases * /* w w w.j a v a 2 s. c o m*/ * @return the relative random URL generated */ @DependsOn({ "selectedBook", "clientType", "monthlyReportYear" }) public String getBalancePropertiesChartURL() { if (bookSelection.getSelectedBook() == null || !getIsAllBooks()) { return ""; } List<Annotation> anotations = getAnnotationsInAscendingDateOrder(Optional.<Integer>absent()); Collection<Annotation> annotationsFromPropertiesBooks = Collections2.filter(anotations, new Predicate<Annotation>() { @Override public boolean apply(Annotation annotation) { return annotation.getBook() instanceof PropertyBook; } }); Multimap<Integer, Annotation> yearToBookAnnotationsMultimap = getYearToAnnotationMultimapFromAnnotations( annotationsFromPropertiesBooks); CategoryDataset categoryModel = ChartDataModel.getBalance(monthlyReportYear, yearToBookAnnotationsMultimap, bookSelection, false, Optional.<String>absent()); JFreeChart jfchart = ChartFactory.createLineChart("Saldo de propiedades (viviendas y locales)", "Fecha", "Euros", categoryModel, PlotOrientation.VERTICAL, true, true, false); PrepareChart.prepareBalanceChart(jfchart); return ResourceImageGenerator.getFunction().apply(jfchart); }
From source file:simz1.StackedBarChart.java
public void SweetsGraph() { DefaultCategoryDataset sidata = new DefaultCategoryDataset(); sidata.setValue(si1, "sales", d1); sidata.setValue(si2, "sales", d2); sidata.setValue(si3, "sales", d3); sidata.setValue(si4, "sales", d4); sidata.setValue(si5, "sales", d5); sidata.setValue(si6, "sales", d6); sidata.setValue(si7, "sales", d7); JFreeChart chart5 = ChartFactory.createLineChart("Sales of Sweet items last week", "Date", "sales", sidata, PlotOrientation.VERTICAL, false, true, false); CategoryPlot c5 = chart5.getCategoryPlot(); c5.setBackgroundPaint(Color.lightGray); c5.getRenderer().setSeriesPaint(0, Color.PINK); //c5.setRangeGridlinePaint(Color.pink); ChartPanel c5Panel = new ChartPanel(chart5); mhp.chartPanel.removeAll();/* w w w. j a v a2 s .c om*/ mhp.chartPanel.add(c5Panel); }
From source file:stockit.allStocks.java
private void stockPerfmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stockPerfmActionPerformed // TODO add your handling code here: DefaultCategoryDataset dataset = new DefaultCategoryDataset(); int row = table.getSelectedRow(); if (row != -1) { //dataset.setValue(, "", table.getValueAt(0,1).toString()); String selectedStock = table.getValueAt(row, 0).toString(); try {/* w w w . j av a 2 s . co m*/ DBConnection dbcon = new DBConnection(); dbcon.establishConnection(); Statement stmt = dbcon.con.createStatement(); ResultSet rs = stmt .executeQuery("Select stock_daily_performance.Closing_Price, stock_daily_performance.Date\n" + "FROM stock_daily_performance, stock\n" + "WHERE stock_daily_performance.StockID = stock.StockID AND stock.StockID = '" + selectedStock + "'" + "AND Date IN\n" + "( Select * from\n" + "(\n" + "SELECT Date \n" + "FROM stock_daily_performance \n" + "WHERE StockID = stockID \n" + "ORDER BY Date ASC\n" + ") temp_table)\n" + " "); while (rs.next()) { String formattedDate = rs.getString("Date"); int closing_price = rs.getInt("Closing_Price"); System.out.println("Closing Price: " + closing_price); System.out.println("Date: " + formattedDate); dataset.setValue(closing_price, "value", formattedDate); } dbcon.con.close(); } catch (Exception ex) { Logger.getLogger(clientLogin.class.getName()).log(Level.SEVERE, null, ex); } String stockName = table.getValueAt(row, 1).toString(); JFreeChart chart = ChartFactory.createLineChart(stockName + " Stock Performance", "Date", "Value", dataset, PlotOrientation.VERTICAL, false, false, false); Color c = new Color(240, 240, 240, 0); chart.setBackgroundPaint(c); CategoryPlot catPlot = chart.getCategoryPlot(); catPlot.setRangeGridlinePaint(Color.BLACK); //set interval of Y-axis ticks (tick every 5 units) NumberAxis yAxis = (NumberAxis) catPlot.getRangeAxis(); yAxis.setTickUnit(new NumberTickUnit(5)); //set y-axis labels as currency types ($) NumberFormat currency = NumberFormat.getCurrencyInstance(); yAxis.setNumberFormatOverride(currency); //setting number of lines an x-axis label is displayed on CategoryAxis categoryAxis = catPlot.getDomainAxis(); categoryAxis.setMaximumCategoryLabelLines(4); graphPanel.setLayout(new java.awt.BorderLayout()); ChartPanel chartPanel = new ChartPanel(chart); graphPanel.removeAll(); graphPanel.add(chartPanel, BorderLayout.CENTER); graphPanel.validate(); graphPanel.repaint(); } }
From source file:UserInterface.PDCPrimaryDoctorRole.PDCPrimaryDoctorReportsJPanel.java
private void populateGraphs(Patient patient, String attribute) { int lowerNormal = 0; int higherNormal = 0; int yAxis = 0; DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset(); for (VitalSigns vitalSigns : patient.getVitalSignsHistory().getVitalSignsHistory()) { if (attribute.equalsIgnoreCase("ECG")) { yAxis = vitalSigns.getEcg(); lowerNormal = 46;//from w w w . ja v a 2 s .c om higherNormal = 50; } else if (attribute.equalsIgnoreCase("HEART RATE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 60; higherNormal = 90; } else if (attribute.equalsIgnoreCase("RESPIRATORY RATE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 12; higherNormal = 25; } else if (attribute.equalsIgnoreCase("WEIGHT IN KG")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 80; higherNormal = 85; } else if (attribute.equalsIgnoreCase("SYSTOLIC BLOOD PRESSURE")) { yAxis = vitalSigns.getHeartRate(); lowerNormal = 90; higherNormal = 120; } Date currentTimeStamp = new Date(); int currentTime = (int) (currentTimeStamp.getTime()) / (1000 * 60); int vitalSignsTime = (int) vitalSigns.getTimeStamp().getTime() / (1000 * 60); if (currentTime - vitalSignsTime <= 1) { line_chart_dataset.addValue(yAxis, attribute, vitalSigns.getTimeStamp()); } } JFreeChart lineChart = ChartFactory.createLineChart(attribute + " Over Time", "Time", attribute, line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); CategoryPlot pi = lineChart.getCategoryPlot(); pi.setRangeGridlinePaint(Color.WHITE); pi.getRenderer().setSeriesPaint(0, Color.GREEN); pi.setBackgroundPaint(Color.BLACK); ValueMarker marker = new ValueMarker(lowerNormal); marker.setLabel("Normal Range"); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelPaint(Color.WHITE); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); marker.setPaint(Color.CYAN); pi.addRangeMarker(marker); ValueMarker marker2 = new ValueMarker(higherNormal); marker2.setLabel("Normal Range"); marker2.setLabelPaint(Color.WHITE); marker2.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker2.setLabelTextAnchor(TextAnchor.TOP_RIGHT); marker2.setPaint(Color.CYAN); pi.addRangeMarker(marker2); reportJPanel.setLayout(new java.awt.BorderLayout()); ChartPanel panel = new ChartPanel(lineChart); reportJPanel.add(panel, BorderLayout.CENTER); reportJPanel.validate(); }
From source file:org.pau.assetmanager.viewmodel.MonthlyReportViewModel.java
/** * This method generates an image of a chart of the evolution of the total * amount of money for the stocks book selection for a year in a monthly basis * /* w w w . j av a2 s . c o m*/ * @return the relative random URL generated */ @DependsOn({ "selectedBook", "clientType", "monthlyReportYear" }) public String getBalanceStocksChartURL() { if (bookSelection.getSelectedBook() == null) { return ""; } if (!getIsAllBooks()) { return ""; } List<Annotation> anotations = getAnnotationsInAscendingDateOrder(Optional.<Integer>absent()); Collection<Annotation> annotationsFromStocksBooks = Collections2.filter(anotations, new Predicate<Annotation>() { @Override public boolean apply(Annotation annotation) { return annotation.getBook() instanceof StocksBook; } }); Multimap<Integer, Annotation> yearToStocksBooksMultimap = getYearToAnnotationMultimapFromAnnotations( annotationsFromStocksBooks); CategoryDataset categoryModel = ChartDataModel.getBalance(monthlyReportYear, yearToStocksBooksMultimap, bookSelection, false, Optional.<String>absent()); JFreeChart jfchart = ChartFactory.createLineChart("Saldo de inversin en bolsa", "Fecha", "Euros", categoryModel, PlotOrientation.VERTICAL, true, true, false); PrepareChart.prepareBalanceChart(jfchart); return ResourceImageGenerator.getFunction().apply(jfchart); }
From source file:org.oscarehr.web.OcanReportingAction.java
private JFreeChart generateChart(String title, String needType, String clientNeedType, List<IndividualNeedsOverTimeChartBean> chartBeanList) { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (IndividualNeedsOverTimeChartBean chartBean : chartBeanList) { dataset.addValue(chartBean.getNeedsCountMap().get(needType), "Staff", chartBean.getLabel()); }//from w w w .j av a 2 s .c o m for (IndividualNeedsOverTimeChartBean chartBean : chartBeanList) { dataset.addValue(chartBean.getNeedsCountMap().get(clientNeedType), "Consumer", chartBean.getLabel()); } JFreeChart chart = ChartFactory.createLineChart(title, // chart title "OCANs", // x axis label "# of " + WordUtils.capitalize(needType) + " Needs", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); LineAndShapeRenderer renderer = new LineAndShapeRenderer(); plot.setRenderer(renderer); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickMarksVisible(true); return chart; }
From source file:javaapplication1.AlgoritmoGenetico.java
public void graficarErrorPatron(double[] errorPatron) { //Fuentes de datos DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset(); for (int i = 0; i < errorPatron.length; i++) { line_chart_dataset.setValue(errorPatron[i], "Error", String.valueOf(i + 1)); }/*from w w w . j a va 2s .co m*/ // Creando el Grafico JFreeChart chart = ChartFactory.createLineChart("Errores por patron", "patrones", "Errores", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); // Mostrar Grafico ChartPanel chartPanel = new ChartPanel(chart); panel1.removeAll(); panel1.add(chartPanel, BorderLayout.CENTER); panel1.validate(); }
From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java
/** * This is a helper method for creating charts and is split off as it does * only the chart creation and tweaking of a category chart. All of the * decisions for what columns are defined as what and how the data is stored * should be done in the method that calls this. * <p>//w w w.j a va2 s. c o m * Given a dataset and other chart properties this will create an * appropriate JFreeChart. * @param c * * @param dataset * The data to create a chart from. * @param chartType * The type of chart to create for the category dataset. * @param legendPosition * The position where the legend should appear. * @param chartName * The title of the chart. * @param yaxisName * The title of the Y axis. * @param xaxisName * The title of the X axis. * @return A JFreeChart that represents the dataset given. */ private static JFreeChart createCategoryChartFromDataset(Chart c, CategoryDataset dataset, ChartType chartType, LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) { if (chartType == null || dataset == null) { return null; } boolean showLegend = !legendPosition.equals(LegendPosition.NONE); JFreeChart chart; ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme()); BarRenderer.setDefaultBarPainter(new StandardBarPainter()); if (chartType == ChartType.BAR) { chart = ChartFactory.createBarChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL, showLegend, true, false); } else if (chartType == ChartType.PIE) { chart = createPieChart(chartName, dataset, TableOrder.BY_ROW, showLegend, true, false); } else if (chartType == ChartType.CATEGORY_LINE) { chart = ChartFactory.createLineChart(chartName, xaxisName, yaxisName, dataset, PlotOrientation.VERTICAL, showLegend, true, false); } else { throw new IllegalArgumentException("Unknown chart type " + chartType + " for a category dataset."); } if (chart == null) return null; if (legendPosition != LegendPosition.NONE) { chart.getLegend().setPosition(legendPosition.getRectangleEdge()); //chart.getTitle().setPadding(4,4,15,4); } if (chart.getPlot() instanceof MultiplePiePlot) { MultiplePiePlot mplot = (MultiplePiePlot) chart.getPlot(); PiePlot plot = (PiePlot) mplot.getPieChart().getPlot(); plot.setLabelLinkStyle(PieLabelLinkStyle.CUBIC_CURVE); if (showLegend) { // for now, legend and items labels are mutually exclusive. Could make this a user pref. plot.setLabelGenerator(null); } } if (!c.isAutoYAxisRange()) { CategoryPlot plot = chart.getCategoryPlot(); ValueAxis axis = plot.getRangeAxis(); axis.setAutoRange(false); axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange()); } return chart; }