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:org.jfree.chart.demo.SecondaryDatasetDemo2.java
/** * Constructs a new demonstration application. * * @param title the frame title.//from w w w. j a va 2 s .c o m */ public SecondaryDatasetDemo2(final String title) { super(title); final CategoryDataset dataset1 = createRandomDataset("Series 1"); final JFreeChart chart = ChartFactory.createLineChart("Secondary Dataset Demo 2", "Category", "Value", dataset1, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); this.plot = chart.getCategoryPlot(); this.plot.setBackgroundPaint(Color.lightGray); this.plot.setDomainGridlinePaint(Color.white); this.plot.setRangeGridlinePaint(Color.white); // this.plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 4, 4, 4, 4)); final NumberAxis rangeAxis = (NumberAxis) this.plot.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); final JPanel content = new JPanel(new BorderLayout()); final ChartPanel chartPanel = new ChartPanel(chart); content.add(chartPanel); final JButton button1 = new JButton("Add Dataset"); button1.setActionCommand("ADD_DATASET"); button1.addActionListener(this); final JButton button2 = new JButton("Remove Dataset"); button2.setActionCommand("REMOVE_DATASET"); button2.addActionListener(this); final JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(button1); buttonPanel.add(button2); content.add(buttonPanel, BorderLayout.SOUTH); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(content); }
From source file:sas.BarChart.java
public static JFreeChart createChart(CategoryDataset categorydataset, String name, String type, String t) { JFreeChart jfreechart = ChartFactory.createLineChart(name, null, type, categorydataset, PlotOrientation.VERTICAL, false, true, false); jfreechart.addSubtitle(new TextTitle(t)); TextTitle texttitle = new TextTitle(""); texttitle.setFont(new Font("SansSerif", 0, 10)); texttitle.setPosition(RectangleEdge.BOTTOM); texttitle.setHorizontalAlignment(HorizontalAlignment.CENTER); jfreechart.addSubtitle(texttitle);//from w w w. j a v a2 s .co m CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setRangePannable(true); categoryplot.setRangeGridlinesVisible(false); java.net.URL url = (BarChart.class).getClassLoader().getResource("line_Chart_example.png"); if (url != null) { ImageIcon imageicon = new ImageIcon(url); jfreechart.setBackgroundImage(imageicon.getImage()); categoryplot.setBackgroundPaint(null); } NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); ChartUtilities.applyCurrentTheme(jfreechart); LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); lineandshaperenderer.setBaseShapesVisible(true); lineandshaperenderer.setDrawOutlines(true); lineandshaperenderer.setUseFillPaint(true); lineandshaperenderer.setBaseFillPaint(Color.white); lineandshaperenderer.setSeriesStroke(0, new BasicStroke(3F)); lineandshaperenderer.setSeriesOutlineStroke(0, new BasicStroke(2.0F)); lineandshaperenderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(-5D, -5D, 10D, 10D)); return jfreechart; }
From source file:org.openmrs.module.vcttrac.web.view.chart.EvolutionOfClientRegisteredPerDay.java
/** * @see org.openmrs.module.vcttrac.web.view.chart.AbstractChartView#createChart(java.util.Map, * javax.servlet.http.HttpServletRequest) */// ww w . j a va2 s . c om @Override protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { String categoryAxisLabel = VCTTracUtil.getMessage("vcttrac.graph.evolution.yAxis.days", null); String valueAxisLabel = VCTTracUtil.getMessage("vcttrac.graph.evolution.xAxis.numberofclient", null); int numberOfDays = 7, dayFormat = 1; if (request.getParameter("graphCategory") != null) { if (request.getParameter("graphCategory").trim().compareTo("2") == 0) { Date d = new Date(); d.setDate(1); d.setMonth((new Date()).getMonth()); d.setYear((new Date()).getYear()); numberOfDays = (int) (((new Date()).getTime() - d.getTime()) / VCTTracConstant.ONE_DAY_IN_MILLISECONDS); categoryAxisLabel = VCTTracUtil.getMessage("vcttrac.month." + ((new Date()).getMonth() + 1), null); dayFormat = 2; } } String title = ""; title = VCTTracUtil.getMessage("vcttrac.graph.evolution.client.received", null); JFreeChart chart = ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, createDataset(numberOfDays, dayFormat), // data PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setUpperMargin(0.15); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // customise the renderer... LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setItemLabelsVisible(true); return chart; }
From source file:edu.jhuapl.graphs.jfreechart.JFreeChartDualAxisGraphSource.java
@Override public JFreeChart createChart(String title, String xLabel, String yLabel, CategoryDataset dataset, boolean legend, boolean graphToolTip) { PlotOrientation orientation = getParam(JFreeChartBarGraphSource.PLOT_ORIENTATION, PlotOrientation.class, JFreeChartBarGraphSource.DEFAULT_PLOT_ORIENTATION); // create the base plot, which is the time series graph JFreeChart dualAxisGraph = ChartFactory.createLineChart(title, xLabel, tsLabel, tsDataset, orientation, legend, graphToolTip, false); // add the bar graph data to the plot dualAxisGraph.getCategoryPlot().setDataset(1, barDataset); // create the second y-axis dualAxisGraph.getCategoryPlot().setRangeAxis(1, new NumberAxis(barLabel)); dualAxisGraph.getCategoryPlot().mapDatasetToRangeAxis(1, 1); // create separate renderers for the time series and bar graphs to be // overlaid on the same plot CategoryLineGraphRenderer tsRenderer = new CategoryLineGraphRenderer(tsData); CategoryBarGraphRenderer barRenderer = new CategoryBarGraphRenderer(barData); setupLineRenderer(tsRenderer);//from w w w .jav a2 s . c om setupBarRenderer(barRenderer); dualAxisGraph.getCategoryPlot().setRenderer(0, tsRenderer); dualAxisGraph.getCategoryPlot().setRenderer(1, barRenderer); return dualAxisGraph; }
From source file:br.upe.ecomp.dosa.controller.chart.FileLineChartDirectorManager.java
private JFreeChart createChart(String title, String xLabel, String yLabel, CategoryDataset dataset, boolean logarithmicYAxis) { // create the chart... final JFreeChart chart = ChartFactory.createLineChart("", // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );//from w w w. j a v a 2 s . c om // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // legend.setShapeScaleX(1.5); // legend.setShapeScaleY(1.5); // legend.setDisplaySeriesLines(true); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(true); return chart; }
From source file:view.PnIncome.java
private ChartPanel getChartPanel(String title, String type, DefaultCategoryDataset dataset) { JFreeChart lineChart = ChartFactory.createLineChart(title, "Thu nhp", type, dataset, PlotOrientation.VERTICAL, true, true, false); ChartPanel chartPanel = new ChartPanel(lineChart); return chartPanel; }
From source file:com.thalesgroup.hudson.plugins.klocwork.graph.KloTrendGraph.java
@Override protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );/* w w w .java2 s .c o m*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(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()); rangeAxis.setLowerBound(0); rangeAxis.setAutoRange(true); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); ColorPalette.apply(renderer); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:org.matsim.core.utils.charts.LineChart.java
private JFreeChart createChart(final String title, final String categoryAxisLabel, final String valueAxisLabel, final CategoryDataset dataset) { return ChartFactory.createLineChart(title, categoryAxisLabel, valueAxisLabel, dataset, PlotOrientation.VERTICAL, true, // legend? false, // tooltips? false // URLs? );/*from w w w . j a v a 2s .com*/ }
From source file:org.no_ip.xeps.jntpplot.Plotter.java
public void chart() { DefaultCategoryDataset statsDataset = new DefaultCategoryDataset(); System.out.println(stats);/*from w w w . java 2 s . c o m*/ for (List<String> stat : stats) { for (int i = 1; i < statsLabels.size(); i++) { BigDecimal bd = new BigDecimal(stat.get(i)); statsDataset.addValue( //(Number) Long.valueOf(stat.get(i)), bd, (Comparable) statsLabels.get(i), (Comparable) stat.get(0)); } } // Chart bars if instructed to if (chartType == "bar") { JFreeChart barChartObject = ChartFactory.createBarChart(plotLabel, statsLabels.get(0), yLabel, statsDataset, PlotOrientation.VERTICAL, true, true, false); int width = 1280; int height = 1024; File barChart = new File(output); try { ChartUtilities.saveChartAsJPEG(barChart, barChartObject, width, height); } catch (IOException ex) { java.util.logging.Logger.getLogger(Plotter.class.getName()).log(Level.SEVERE, null, ex); logger.error("Failed to output linechart JPEG @ " + output + ": " + ex); } // Default to line charts } else { JFreeChart lineChartObject = ChartFactory.createLineChart(plotLabel, statsLabels.get(0), yLabel, statsDataset, PlotOrientation.VERTICAL, true, true, false); int width = 1280; int height = 1024; File lineChart = new File(output); try { ChartUtilities.saveChartAsJPEG(lineChart, lineChartObject, width, height); } catch (IOException ex) { java.util.logging.Logger.getLogger(Plotter.class.getName()).log(Level.SEVERE, null, ex); logger.error("Failed to output linechart JPEG @ " + output + ": " + ex); } } }
From source file:com.liferay.samplestrutsliferay.struts.action.ViewChartAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try {//from www. jav a2s . c om if (_log.isInfoEnabled()) { _log.info("execute"); } String attrName = "chart_name"; // Application scoped session attributes can be fetched from the // servlet directly. Portlet scoped session attributes can be // fetched from Sun's PortletSessionUtil. HttpSession session = request.getSession(); String chartName = (String) session.getAttribute(attrName); //(String)_getAttribute(request, attrName); // Chart String chartType = request.getParameter("chart_type"); CategoryDataset dataset = _getDataset(); String xName = "Soda"; String yName = "Votes"; JFreeChart chart = null; if (chartType.equals("area")) { chart = ChartFactory.createAreaChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("horizontal_bar")) { chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.HORIZONTAL, true, false, false); } else if (chartType.equals("line")) { chart = ChartFactory.createLineChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else if (chartType.equals("vertical_bar")) { chart = ChartFactory.createBarChart(chartName, xName, yName, dataset, PlotOrientation.VERTICAL, true, false, false); } else { PieDataset pieData = DatasetUtilities.createPieDatasetForRow(dataset, 0); chart = ChartFactory.createPieChart(chartName, pieData, true, false, false); } response.setContentType("image/jpeg"); OutputStream out = response.getOutputStream(); ChartUtilities.writeChartAsJPEG(out, chart, 400, 400); return mapping.findForward("/common/null.jsp"); } catch (Exception e) { request.setAttribute(PageContext.EXCEPTION, e); return mapping.findForward("/common/error.jsp"); } }