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:hudson.plugins.emma.portlet.chart.EmmaBuilderTrendChart.java
/** * Creates a graph for Emma Coverage results. * * @param summaries/* w ww .j a v a2 s .c om*/ * HashMap(key = run date and value = Instrumentation tests * results) * @param widthParam * the chart width * @param heightParam * the chart height * @return Graph (JFreeChart) */ private static Graph createTrendChart(final Map<LocalDate, EmmaCoverageResultSummary> summaries, int widthParam, int heightParam) { return new Graph(-1, widthParam, heightParam) { @Override protected JFreeChart createGraph() { // Show empty chart if (summaries == null) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); return chart; } int lineNumber = 0; JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); // Line thickness CategoryItemRenderer renderer = plot.getRenderer(); BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber, stroke); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(Constants.DEFAULT_MARGIN); domainAxis.setUpperMargin(Constants.DEFAULT_MARGIN); domainAxis.setCategoryMargin(Constants.DEFAULT_MARGIN); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(Constants.UPPER_BOUND); rangeAxis.setLowerBound(Constants.LOWER_BOUND); return chart; } }; }
From source file:hudson.plugins.karma.portlet.chart.KarmaBuilderTrendChart.java
/** * Creates a graph for Karma Coverage results. * * @param summaries/*from ww w .j a va2 s . c o m*/ * HashMap(key = run date and value = Instrumentation tests * results) * @param widthParam * the chart width * @param heightParam * the chart height * @return Graph (JFreeChart) */ private static Graph createTrendChart(final Map<LocalDate, KarmaCoverageResultSummary> summaries, int widthParam, int heightParam) { return new Graph(-1, widthParam, heightParam) { @Override protected JFreeChart createGraph() { // Show empty chart if (summaries == null) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); return chart; } int lineNumber = 0; JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); // Line thickness CategoryItemRenderer renderer = plot.getRenderer(); BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber, stroke); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(Constants.DEFAULT_MARGIN); domainAxis.setUpperMargin(Constants.DEFAULT_MARGIN); domainAxis.setCategoryMargin(Constants.DEFAULT_MARGIN); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(Constants.UPPER_BOUND); rangeAxis.setLowerBound(Constants.LOWER_BOUND); return chart; } }; }
From source file:hudson.plugins.jacoco.portlet.chart.JacocoBuilderTrendChart.java
/** * Creates a graph for JaCoCo Coverage results. * * @param summaries/*from www . j a v a 2 s . c o m*/ * HashMap(key = run date and value = Instrumentation tests * results) * @param widthParam * the chart width * @param heightParam * the chart height * @return Graph (JFreeChart) */ private static Graph createTrendChart(final Map<LocalDate, JacocoCoverageResultSummary> summaries, int widthParam, int heightParam) { return new Graph(-1, widthParam, heightParam) { @Override protected JFreeChart createGraph() { // Show empty chart if (summaries == null) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); return chart; } int lineNumber = 0; JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); // Line thickness CategoryItemRenderer renderer = plot.getRenderer(); BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber, stroke); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(Constants.DEFAULT_MARGIN); domainAxis.setUpperMargin(Constants.DEFAULT_MARGIN); domainAxis.setCategoryMargin(Constants.DEFAULT_MARGIN); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); //rangeAxis.setUpperBound(Constants.UPPER_BOUND); rangeAxis.setLowerBound(Constants.LOWER_BOUND); return chart; } }; }
From source file:hudson.plugins.codecover.portlet.chart.CodeCoverBuilderTrendChart.java
/** * Creates a graph for CodeCover Coverage results. * * @param summaries/*from ww w . j a v a2 s .com*/ * HashMap(key = run date and value = Instrumentation tests * results) * @param widthParam * the chart width * @param heightParam * the chart height * @return Graph (JFreeChart) */ private static Graph createTrendChart(final Map<LocalDate, CodeCoverCoverageResultSummary> summaries, int widthParam, int heightParam) { return new Graph(-1, widthParam, heightParam) { @Override protected JFreeChart createGraph() { // Show empty chart if (summaries == null) { JFreeChart chart = ChartFactory.createStackedAreaChart(null, Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, null, PlotOrientation.VERTICAL, true, false, false); return chart; } int lineNumber = 0; JFreeChart chart = ChartFactory.createLineChart("", Constants.AXIS_LABEL, Constants.AXIS_LABEL_VALUE, buildDataSet(summaries), PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); // Line thickness CategoryItemRenderer renderer = plot.getRenderer(); BasicStroke stroke = new BasicStroke(Constants.LINE_THICKNESS, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber++, stroke); renderer.setSeriesStroke(lineNumber, stroke); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setForegroundAlpha(Constants.FOREGROUND_ALPHA); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(Constants.DEFAULT_MARGIN); domainAxis.setUpperMargin(Constants.DEFAULT_MARGIN); domainAxis.setCategoryMargin(Constants.DEFAULT_MARGIN); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperBound(Constants.UPPER_BOUND); rangeAxis.setLowerBound(Constants.LOWER_BOUND); return chart; } }; }
From source file:edu.ku.brc.specify.plugins.ipadexporter.ChartHelper.java
/** * @param list//from w w w . j a va 2 s. com * @param title * @param xAxisTitle * @param yAxisTitle * @param isVertical * @param width * @param height */ public JFreeChart createLineChart(final List<Object> list, final String title, final String xAxisTitle, final String yAxisTitle, final boolean isVertical, final int width, final int height) { DefaultCategoryDataset catDataSet = new DefaultCategoryDataset(); for (int i = 0; i < list.size(); i++) { Object xVal = list.get(i++); Object yVal = list.get(i); double xv = getDbl(xVal); numMin = Math.min(numMin, xv); numMax = Math.max(numMax, xv); catDataSet.addValue(getDbl(yVal), "X", xVal.toString()); } /*XYDataset dataset = createXYDataSet(list); JFreeChart chart = ChartFactory.createXYLineChart( title, // chart title xAxisTitle, // domain axis label yAxisTitle, // range axis label dataset, // data isVertical ? PlotOrientation.VERTICAL : PlotOrientation.HORIZONTAL, false, // include legend true, // tooltips? false // URLs? ); XYPlot xyplot = chart.getXYPlot(); NumberAxis numberAxis = (NumberAxis) xyplot.getDomainAxis(); numberAxis.setRange(numMin, numMax); //ValueAxis axis = xyplot.getDomainAxis(); //axis = xyplot.getRangeAxis(); //((NumberAxis) axis).setTickUnit(new NumberTickUnit(1)); //axis.setRange(1870,2010);*/ /* JFreeChart jfreechart = ChartFactory.createLineChart3D( title, xAxisTitle, yAxisTitle, catDataSet, PlotOrientation.VERTICAL, false, true, false); jfreechart.setBackgroundPaint(new Color(187, 187, 221)); CategoryPlot categoryplot = (CategoryPlot)jfreechart.getPlot(); NumberAxis numberaxis = (NumberAxis)categoryplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryItemRenderer renderer = categoryplot.getRenderer(); renderer.setSeriesPaint(0, new Color(95, 158, 160)); renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY); */ JFreeChart jfreechart = ChartFactory.createLineChart(title, xAxisTitle, yAxisTitle, catDataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setRangeGridlinePaint(Color.DARK_GRAY); categoryplot.setBackgroundPaint(null); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); CategoryItemRenderer renderer = categoryplot.getRenderer(); renderer.setSeriesPaint(0, new Color(95, 158, 160)); renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY); BasicStroke lineStroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); renderer.setBaseStroke(lineStroke); renderer.setBaseOutlineStroke(lineStroke); renderer.setSeriesStroke(0, lineStroke); //renderer.setOutlineStroke(lineStroke); //renderer.setStroke(lineStroke); return jfreechart; }
From source file:hudson.plugins.codeviation.RepositoryView.java
private JFreeChart createChart(CategoryDataset dataset, int max) { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused "counts", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );/*from w w w. j a va 2 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.setUpperBound(max * 1.2); rangeAxis.setLowerBound(0); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setStroke(new BasicStroke(4.0f)); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:guineu.modules.filter.report.intensitiesReport.ReportTask.java
/** * Create the chart and save it into a png file. * @param dataset//from ww w . jav a 2s.co m * @param lipidName */ private void createChart(CategoryDataset dataset, String lipidName) { try { String fieldY; if (this.useArea) { fieldY = "Area"; } else { fieldY = "Heights"; } JFreeChart chart = ChartFactory.createLineChart("Intensities", "Samples", fieldY, dataset, PlotOrientation.VERTICAL, false, false, false); // Chart characteristics CategoryPlot plot = (CategoryPlot) chart.getPlot(); final NumberAxis axis = (NumberAxis) plot.getRangeAxis(); axis.setAutoRangeIncludesZero(false); LineAndShapeRenderer categoryRenderer = new LineAndShapeRenderer(); categoryRenderer.setSeriesLinesVisible(0, false); categoryRenderer.setSeriesShapesVisible(0, true); plot.setRenderer(categoryRenderer); // Save all the charts in the folder choosen by the user ChartUtilities.saveChartAsPNG(new File(this.reportFileName + "/" + fieldY + ":" + lipidName + ".png"), chart, 1000, 500); } catch (IOException ex) { Logger.getLogger(ReportTask.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:edu.ucla.stat.SOCR.chart.demo.EventFrequencyDemo1.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 www.j av a 2 s . co m // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); CategoryPlot plot = chart.getCategoryPlot(); LineAndShapeRenderer renderer = new LineAndShapeRenderer(false, true); plot.setRenderer(renderer); return chart; }
From source file:sipl.recursos.Graficar.java
public void PrestamosY(int[][] values, int n, String direccion, String tiempo, String titulo) { try {/*from w w w . ja v a2 s .c o m*/ DefaultCategoryDataset dataset = new DefaultCategoryDataset(); for (int j = 0; j < n; j++) { dataset.addValue(values[j][1], "Cantidad de Prstamos", "" + values[j][0]); } JFreeChart chart = ChartFactory.createLineChart(titulo, tiempo, "Cantidad", dataset, PlotOrientation.VERTICAL, true, true, true); try { ChartUtilities.saveChartAsJPEG(new File(direccion), chart, 500, 500); } catch (IOException e) { System.out.println("Error al abrir el archivo"); } } catch (Exception e) { System.out.println(e); } }
From source file:org.jfree.chart.demo.LineChartDemo5.java
/** * Creates a sample chart./*from w w w . ja v a 2 s.c o m*/ * * @param dataset the dataset. * * @return a chart. */ private JFreeChart createChart(final CategoryDataset dataset) { final JFreeChart chart = ChartFactory.createLineChart("Line Chart Demo 5", // chart title "Type", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); final Shape[] shapes = new Shape[3]; int[] xpoints; int[] ypoints; // right-pointing triangle xpoints = new int[] { -3, 3, -3 }; ypoints = new int[] { -3, 0, 3 }; shapes[0] = new Polygon(xpoints, ypoints, 3); // vertical rectangle shapes[1] = new Rectangle2D.Double(-2, -3, 3, 6); // left-pointing triangle xpoints = new int[] { -3, 3, 3 }; ypoints = new int[] { 0, -3, 3 }; shapes[2] = new Polygon(xpoints, ypoints, 3); final DrawingSupplier supplier = new DefaultDrawingSupplier(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, shapes); final CategoryPlot plot = chart.getCategoryPlot(); plot.setDrawingSupplier(supplier); chart.setBackgroundPaint(Color.yellow); // set the stroke for each series... plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 6.0f, 6.0f }, 0.0f)); plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f)); // customise the renderer... final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); // renderer.setDrawShapes(true); renderer.setItemLabelsVisible(true); // renderer.setLabelGenerator(new StandardCategoryLabelGenerator()); // customise the range axis... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setUpperMargin(0.12); return chart; }