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.wpi.cs.wpisuitetng.modules.requirementsmanager.view.charts.AbstractRequirementStatistics.java
protected JFreeChart buildLineChart(final String title, final String category, final String axisLabel) { final JFreeChart chart = ChartFactory.createLineChart(title, category, axisLabel, toCategoryDataset(category), PlotOrientation.VERTICAL, false, false, false); final CategoryPlot xyPlot = (CategoryPlot) chart.getPlot(); final NumberAxis range = (NumberAxis) xyPlot.getRangeAxis(); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:UI.Graphic.java
private void init2() { panel = new JPanel(); getContentPane().add(panel);// w w w .j a v a 2 s . c om // Fuente de Datos DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset(); for (int i = 0; i < experiment2.getMedia().size(); i++) { line_chart_dataset.addValue(experiment2.getMedia().get(i), "aptitud", String.valueOf(i)); } // Creando el Grafico JFreeChart chart = ChartFactory.createLineChart("Apitud de las generaciones", "Generacion", "Aptitud", line_chart_dataset, PlotOrientation.VERTICAL, true, true, false); // Mostrar Grafico ChartPanel chartPanel = new ChartPanel(chart); panel.add(chartPanel); }
From source file:com.js.quickestquail.ui.stats.RatingStat.java
private JFreeChart generateChart() { JFreeChart lineChart = ChartFactory.createLineChart( java.util.ResourceBundle.getBundle("i18n/i18n").getString("stat.rating.title"), java.util.ResourceBundle.getBundle("i18n/i18n").getString("stat.rating.xaxis"), java.util.ResourceBundle.getBundle("i18n/i18n").getString("stat.rating.yaxis"), generateDataset(), PlotOrientation.VERTICAL, true, true, false); lineChart.setBackgroundPaint(new Color(0xFF, 0xFF, 0xFF, 0)); lineChart.getPlot().setBackgroundPaint(Color.WHITE); return lineChart; }
From source file:org.openmrs.web.taglib.ShowGraphTag.java
/** * Render graph.//from w w w . j a va2s . c om * * @return return result code */ public int doStartTag() throws JspException { Patient patient = Context.getPatientService().getPatient(patientId); Concept concept = Context.getConceptService().getConceptByName(conceptName); if (concept != null && concept.isNumeric()) { List<Obs> observations = Context.getObsService().getObservationsByPersonAndConcept(patient, concept); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (Obs obs : observations) { dataset.addValue(obs.getValueNumeric(), conceptName, obs.getObsDatetime()); } JFreeChart chart = ChartFactory.createLineChart(conceptName, "Value", "Date", dataset, PlotOrientation.VERTICAL, true, true, false); try { ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); ChartUtilities.writeChartAsPNG(byteArray, chart, width, height); pageContext.getResponse().setContentType("image/png"); pageContext.getResponse().getWriter().write(byteArray.toString()); } catch (IOException e) { log.error(e); } } return EVAL_BODY_BUFFERED; }
From source file:org.operamasks.faces.render.graph.LineChartRenderer.java
protected JFreeChart createChart(UIChart comp) { Dataset dataset = createDataset(comp); JFreeChart chart = null;//www . ja v a2 s. c o m if (dataset instanceof CategoryDataset) { if (comp.isEffect3D()) { chart = ChartFactory.createLineChart3D(null, null, null, (CategoryDataset) dataset, getChartOrientation(comp), false, false, false); } else { chart = ChartFactory.createLineChart(null, null, null, (CategoryDataset) dataset, getChartOrientation(comp), false, false, false); } } else if (dataset instanceof TimeSeriesCollection) { chart = ChartFactory.createTimeSeriesChart(null, null, null, (XYDataset) dataset, false, false, false); ((XYPlot) chart.getPlot()).setOrientation(getChartOrientation(comp)); } else if (dataset instanceof XYDataset) { chart = ChartFactory.createXYLineChart(null, null, null, (XYDataset) dataset, getChartOrientation(comp), false, false, false); } return chart; }
From source file:org.pentaho.plugin.jfreereport.reportcharts.LineChartExpression.java
protected JFreeChart computeCategoryChart(final CategoryDataset dataset) { final PlotOrientation orientation = computePlotOrientation(); if (isThreeD()) { final JFreeChart chart = ChartFactory.createLineChart3D(computeTitle(), getCategoryAxisLabel(), getValueAxisLabel(), dataset, orientation, isShowLegend(), false, false); chart.getCategoryPlot().setDomainAxis(new FormattedCategoryAxis3D(getCategoryAxisLabel(), getCategoricalAxisMessageFormat(), getRuntime().getResourceBundleFactory().getLocale())); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); configureLogarithmicAxis(plot);/*from w w w.ja va 2 s .c o m*/ return chart; } else { final JFreeChart chart = ChartFactory.createLineChart(computeTitle(), getCategoryAxisLabel(), getValueAxisLabel(), dataset, orientation, isShowLegend(), false, false); chart.getCategoryPlot().setDomainAxis(new FormattedCategoryAxis(getCategoryAxisLabel(), getCategoricalAxisMessageFormat(), getRuntime().getResourceBundleFactory().getLocale())); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); configureLogarithmicAxis(plot); return chart; } }
From source file:se.backede.jeconomix.forms.report.TransactionReport.java
public void addLineChart(Map<String, List<TransactionReportDto>> reports, Boolean average) { JFreeChart lineChart = ChartFactory.createLineChart("TOTAL", "MONTH", "Kr", ReportUtils.createDataset(reports, average), PlotOrientation.VERTICAL, true, true, true); ChartPanel chartPanel = new ChartPanel(lineChart); chartPanel.setPreferredSize(new java.awt.Dimension(lineChartPanel.getWidth(), lineChartPanel.getHeight())); CategoryAxis axis = lineChart.getCategoryPlot().getDomainAxis(); CategoryItemRenderer renderer = lineChart.getCategoryPlot().getRenderer(); ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE1, TextAnchor.HALF_ASCENT_CENTER, TextAnchor.BOTTOM_CENTER, 0); renderer.setBasePositiveItemLabelPosition(position); renderer.setBaseItemLabelGenerator(new CategoryItemLabelGenerator() { @Override/*from w w w . ja va 2 s .co m*/ public String generateLabel(CategoryDataset dataset, int series, int category) { if (average) { if (series == 0) { Number value = dataset.getValue(series, category); String result = value.toString(); // could apply formatting here return result; } } else { Number value = dataset.getValue(series, category); String result = value.toString(); // could apply formatting here return result; } return null; } @Override public String generateRowLabel(CategoryDataset cd, int i) { return null; } @Override public String generateColumnLabel(CategoryDataset cd, int i) { return null; } }); renderer.setBaseItemLabelsVisible(true); lineChartPanel.setLayout(new BorderLayout()); lineChartPanel.add(chartPanel, BorderLayout.NORTH); }
From source file:gavisualizer.LineChart.java
@Override public void generate() { // Creates Line Chart from variables JFreeChart chart = ChartFactory.createLineChart(_title, // chart title _axisLabelDomain, // domain axis label _axisLabelRange, // range axis label _dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend false, // tooltips false // urls );/*from www. ja v a2 s.c o m*/ // Set the Plot to certain colors final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setOutlinePaint(Color.white); // Set Legend to the right of the chart final LegendTitle lt = (LegendTitle) chart.getLegend(); lt.setPosition(RectangleEdge.RIGHT); // Set paints for lines in the chart LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); DefaultDrawingSupplier dw = new DefaultDrawingSupplier(PAINTS, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE); plot.setDrawingSupplier(dw); // Customize stroke width of the series ((AbstractRenderer) renderer).setAutoPopulateSeriesStroke(false); renderer.setBaseStroke(STROKE_WIDTH); renderer.setBaseShapesVisible(false); // Include dashed lines if necessary List<String> rows = _dataset.getRowKeys(); // See if the title includes Downloads (Dashed lines are for Download lines) if (rows.get(rows.size() - 1).endsWith("Downloads")) { // Set the start to half the rows int start = _dataset.getRowCount() / 2; // Create an initial value int init = 0; // Iterate through the Download lines while (start < _dataset.getRowCount()) { // Make sure series and legend have dashes renderer.setSeriesStroke(start, DASHED_STROKE); LegendItemCollection legend = renderer.getLegendItems(); LegendItem li = legend.get(start - 1); li.setLineStroke(DASHED_STROKE); // Make sure the color matches the undashed year renderer.setSeriesPaint(start, renderer.getItemPaint(init, 0)); init++; start++; } } // Customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); _chart = chart; }
From source file:sipl.recursos.Graficar.java
public void Danhos(int[] values, int[] fecha, int n, String direccion, String tiempo, String titulo) { try {// w ww. j av a 2s . co m DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int j = 0; j < n; j++) { dataset.addValue(values[j], "Cantidad de Daos", "" + fecha[j]); } JFreeChart chart = ChartFactory.createLineChart(titulo, tiempo, "Cantidad", dataset, PlotOrientation.VERTICAL, true, true, true); try { ChartUtilities.saveChartAsJPEG(new File(direccion), chart, 700, 500); } catch (IOException e) { System.out.println("Error al abrir el archivo"); } } catch (Exception e) { System.out.println(e); } }
From source file:medic_hospital.WeightTrend.java
public void populateChart(int id) { int[] weightList; double[] dateList; try {// www .ja v a2 s . co m Class.forName("com.mysql.jdbc.Driver"); con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/medic", "root", ""); //To get the number of rows in the result String sql = "Select Count(*) from patient_statistics where patient_id = ?"; pst = con.prepareStatement(sql); pst.setInt(1, id); rs = pst.executeQuery(); if (rs.next()) { weightList = new int[rs.getInt("Count(*)")]; dateList = new double[rs.getInt("Count(*)")]; } else { weightList = new int[1]; dateList = new double[1]; } //To get the statistic sql = "Select weight, date_of_submission from patient_statistics where patient_id = ?"; pst = con.prepareStatement(sql); pst.setInt(1, id); rs = pst.executeQuery(); int li_item = 0; String date = ""; while (rs.next()) { date = ""; weightList[li_item] = rs.getInt("weight"); date = rs.getString("date_of_submission"); date = date.replaceAll("/", ""); date = date.replaceAll(":", ""); date = date.replaceAll(" ", ""); dateList[li_item] = Double.parseDouble(date); li_item++; } JFreeChart chart; chart = ChartFactory.createLineChart("Weight Over Time", "Time", "Weight(kgs)", createDataset(weightList, dateList), PlotOrientation.VERTICAL, true, true, false); //Setting the window contents of the JFrame ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(560, 367)); f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); f.setLayout(new BorderLayout(0, 5)); f.add(chartPanel, BorderLayout.CENTER); f.pack(); f.setVisible(true); } catch (SQLException | ClassNotFoundException ex) { Logger.getLogger(GlucoseTrend.class.getName()).log(Level.SEVERE, null, ex); } }