List of usage examples for org.jfree.chart JFreeChart JFreeChart
public JFreeChart(String title, Font titleFont, Plot plot, boolean createLegend)
From source file:playground.dgrether.analysis.charts.DgModalSplitGroupChart.java
public JFreeChart createChart() { CategoryAxis categoryAxis = this.axisBuilder.createCategoryAxis(xLabel); categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); ValueAxis valueAxis = this.axisBuilder.createValueAxis(yLabel); valueAxis.setRange(0.0, 100.0);/*ww w . jav a2s. c o m*/ DgColorScheme colorScheme = new DgColorScheme(); CategoryPlot plot = new CategoryPlot(); plot.setDomainAxis(categoryAxis); plot.setRangeAxis(valueAxis); plot.setDataset(0, this.dataset); BarRenderer carRenderer = new BarRenderer(); carRenderer.setSeriesPaint(0, colorScheme.COLOR1A); carRenderer.setSeriesPaint(1, colorScheme.COLOR3A); carRenderer.setItemMargin(0.10); plot.setRenderer(0, carRenderer); JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(ChartColor.WHITE); chart.getLegend().setItemFont(this.axisBuilder.getAxisFont()); return chart; }
From source file:com.ewcms.plugin.report.generate.service.chart.ChartGenerationService.java
/** * ?/*from w ww. ja va 2 s . c om*/ * * @param title * @param titleFont * @param categoryAxisLabel * @param valueAxisLabel * @param data ?? * @param orientation ? * @param legend * @param tooltips ???? * @param urls ??URL * @param urlGenerator * * @return ? */ public static JFreeChart createBarChart(String title, java.awt.Font titleFont, String categoryAxisLabel, String valueAxisLabel, CategoryDataset data, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls, CategoryURLGenerator urlGenerator) { CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel); ValueAxis valueAxis = new NumberAxis(valueAxisLabel); BarRenderer renderer = new BarRenderer(); if (tooltips) { // renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator()); renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); } if (urls) { // renderer.setItemURLGenerator(urlGenerator); renderer.setBaseItemURLGenerator(urlGenerator); } CategoryPlot plot = new CategoryPlot(data, categoryAxis, valueAxis, renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, titleFont, plot, legend); return chart; }
From source file:org.jfree.chart.demo.CombinedTimeSeriesDemo1.java
public static JPanel createDemoPanel() { TimeSeries timeseries = new TimeSeries("Annual"); timeseries.add(new Year(1998), 80D); timeseries.add(new Year(1999), 85D); timeseries.add(new Year(2000), 87.599999999999994D); TimeSeriesCollection dataset1 = new TimeSeriesCollection(timeseries); TimeSeries timeseries1 = new TimeSeries("Monthly A"); timeseries1.add(new Month(7, 2000), 85.799999999999997D); timeseries1.add(new Month(8, 2000), 85.799999999999997D); timeseries1.add(new Month(9, 2000), 85.799999999999997D); timeseries1.add(new Month(10, 2000), 86.5D); timeseries1.add(new Month(11, 2000), 86.5D); timeseries1.add(new Month(12, 2000), 86.5D); timeseries1.add(new Month(1, 2001), 87.700000000000003D); timeseries1.add(new Month(2, 2001), 87.700000000000003D); timeseries1.add(new Month(3, 2001), 87.700000000000003D); timeseries1.add(new Month(4, 2001), 88.5D); timeseries1.add(new Month(5, 2001), 88.5D); timeseries1.add(new Month(6, 2001), 88.5D); timeseries1.add(new Month(7, 2001), 90D); timeseries1.add(new Month(8, 2001), 90D); timeseries1.add(new Month(9, 2001), 90D); timeseries1.add(new Month(10, 2001), 90D); timeseries1.add(new Month(11, 2001), 90D); timeseries1.add(new Month(12, 2001), 90D); timeseries1.add(new Month(1, 2002), 90D); timeseries1.add(new Month(2, 2002), 90D); timeseries1.add(new Month(3, 2002), 90D); timeseries1.add(new Month(4, 2002), 90D); timeseries1.add(new Month(5, 2002), 90D); timeseries1.add(new Month(6, 2002), 90D); TimeSeries timeseries2 = new TimeSeries("Monthly B"); timeseries2.add(new Month(7, 2000), 83.799999999999997D); timeseries2.add(new Month(8, 2000), 83.799999999999997D); timeseries2.add(new Month(9, 2000), 83.799999999999997D); timeseries2.add(new Month(10, 2000), 84.5D); timeseries2.add(new Month(11, 2000), 84.5D); timeseries2.add(new Month(12, 2000), 84.5D); timeseries2.add(new Month(1, 2001), 85.700000000000003D); timeseries2.add(new Month(2, 2001), 85.700000000000003D); timeseries2.add(new Month(3, 2001), 85.700000000000003D); timeseries2.add(new Month(4, 2001), 86.5D); timeseries2.add(new Month(5, 2001), 86.5D); timeseries2.add(new Month(6, 2001), 86.5D); timeseries2.add(new Month(7, 2001), 88D); timeseries2.add(new Month(8, 2001), 88D); timeseries2.add(new Month(9, 2001), 88D); timeseries2.add(new Month(10, 2001), 88D); timeseries2.add(new Month(11, 2001), 88D); timeseries2.add(new Month(12, 2001), 88D); timeseries2.add(new Month(1, 2002), 88D); timeseries2.add(new Month(2, 2002), 88D); timeseries2.add(new Month(3, 2002), 88D); timeseries2.add(new Month(4, 2002), 88D); timeseries2.add(new Month(5, 2002), 88D); timeseries2.add(new Month(6, 2002), 88D); TimeSeriesCollection dataset21 = new TimeSeriesCollection(); dataset21.addSeries(timeseries1);/*from w w w. ja va 2 s . c o m*/ dataset21.addSeries(timeseries2); TimeSeries timeseries3 = new TimeSeries("XXX"); timeseries3.add(new Month(7, 2000), 81.5D); timeseries3.add(new Month(8, 2000), 86D); timeseries3.add(new Month(9, 2000), 82D); timeseries3.add(new Month(10, 2000), 89.5D); timeseries3.add(new Month(11, 2000), 88D); timeseries3.add(new Month(12, 2000), 88D); timeseries3.add(new Month(1, 2001), 90D); timeseries3.add(new Month(2, 2001), 89.5D); timeseries3.add(new Month(3, 2001), 90.200000000000003D); timeseries3.add(new Month(4, 2001), 90.599999999999994D); timeseries3.add(new Month(5, 2001), 87.5D); timeseries3.add(new Month(6, 2001), 91D); timeseries3.add(new Month(7, 2001), 89.700000000000003D); timeseries3.add(new Month(8, 2001), 87D); timeseries3.add(new Month(9, 2001), 91.200000000000003D); timeseries3.add(new Month(10, 2001), 84D); timeseries3.add(new Month(11, 2001), 90D); timeseries3.add(new Month(12, 2001), 92D); TimeSeriesCollection dataset22 = new TimeSeriesCollection(timeseries3); // XYBarRenderer renderer1 = new XYBarRenderer(0.20000000000000001D); renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} ({1}, {2})", new SimpleDateFormat("yyyy"), new DecimalFormat("0.00"))); XYPlot plot1 = new XYPlot(dataset1, new DateAxis("Date"), null, renderer1); // XYAreaRenderer renderer21 = new XYAreaRenderer(); XYPlot plot2 = new XYPlot(dataset21, new DateAxis("Date"), null, renderer21); StandardXYItemRenderer renderer22 = new StandardXYItemRenderer(3); renderer22.setBaseShapesFilled(true); plot2.setDataset(1, dataset22); plot2.setRenderer(1, renderer22); plot2.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // NumberAxis valueAxis = new NumberAxis("Value"); valueAxis.setAutoRangeIncludesZero(false); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(valueAxis); combinedPlot.add(plot1, 1); combinedPlot.add(plot2, 4); //chart JFreeChart jfreechart = new JFreeChart("Sample Combined Plot", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, true); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(500, 270)); chartpanel.addChartMouseListener(new ChartMouseListener() { public void chartMouseClicked(ChartMouseEvent chartmouseevent) { System.out.println(chartmouseevent.getEntity()); } public void chartMouseMoved(ChartMouseEvent chartmouseevent) { System.out.println(chartmouseevent.getEntity()); } }); return chartpanel; }
From source file:Presentation.MainWindow.java
/** Ajout la fentre des graphiques de temprature et d'humidit en temps rel */ public void initGraphs() { XYSeriesCollection datasetT = new XYSeriesCollection(); XYSeriesCollection datasetH = new XYSeriesCollection(); datasetT.addSeries(seriesT);/* w w w .j a v a 2 s.c o m*/ datasetH.addSeries(seriesH); XYPlot plotT = new XYPlot(datasetT, new NumberAxis(), new NumberAxis(), new DefaultXYItemRenderer()); XYPlot plotH = new XYPlot(datasetH, new NumberAxis(), new NumberAxis(), new DefaultXYItemRenderer()); //plot.setDataset(1, datasetT); // plot.setRenderer(1, new DefaultXYItemRenderer()); plotH.getRenderer().setSeriesPaint(0, Color.BLUE); JFreeChart chartT = new JFreeChart("Graphique de temprature", JFreeChart.DEFAULT_TITLE_FONT, plotT, true); JFreeChart chartH = new JFreeChart("Graphique d'humidit", JFreeChart.DEFAULT_TITLE_FONT, plotH, true); ChartPanel gPanelT = new ChartPanel(chartT); ChartPanel gPanelH = new ChartPanel(chartH); mPanel.add(gPanelT); mPanel.add(gPanelH); }
From source file:com.projity.pm.graphic.chart.ChartHelper.java
public static JFreeChart createLineChart(final XYDataset dataset) { NumberAxis xAxis = new NumberAxis(null); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(null); XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); removeAxisAndInsets(chart);/* w w w. j a v a2s. co m*/ return chart; }
From source file:com.joey.software.memoryToolkit.MemoryUsagePanel.java
/** * Creates a new application.//from w w w .j a va 2 s. c o m * * @param historyCount * the history count (in milliseconds). */ public MemoryUsagePanel(int historyCount, int interval) { super(new BorderLayout()); // create two series that automatically discard data more than 30 // seconds old... this.total = new TimeSeries("Total Memory", Millisecond.class); this.total.setMaximumItemCount(historyCount); this.free = new TimeSeries("Free Memory", Millisecond.class); this.free.setMaximumItemCount(historyCount); this.used = new TimeSeries("Used Memory", Millisecond.class); this.used.setMaximumItemCount(historyCount); this.max = new TimeSeries("Used Memory", Millisecond.class); this.max.setMaximumItemCount(historyCount); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(this.total); dataset.addSeries(this.free); dataset.addSeries(this.used); dataset.addSeries(this.max); DateAxis domain = new DateAxis("Time"); NumberAxis range = new NumberAxis("Memory"); domain.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); renderer.setSeriesPaint(0, Color.red); renderer.setSeriesPaint(1, Color.green); renderer.setSeriesPaint(2, Color.black); renderer.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); XYPlot plot = new XYPlot(dataset, domain, range, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); domain.setAutoRange(true); domain.setLowerMargin(0.0); domain.setUpperMargin(0.0); domain.setTickLabelsVisible(true); range.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart chart = new JFreeChart("JVM Memory Usage", new Font("SansSerif", Font.BOLD, 24), plot, true); chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); add(chartPanel); gen = new DataGenerator(interval); }
From source file:ascensionxyplot.AscensionXYPlot.java
/** * Creates a combined chart./*ww w .j av a2s. c o m*/ * * @return The combined chart. */ private JFreeChart createCombinedChart(File dataFile) { // create subplot 1... final XYDataset data1 = createDataset1(dataFile); final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Range 1"); final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); // add secondary axis // subplot1.setDataset(1, createDataset2()); // final NumberAxis axis2 = new NumberAxis("Range Axis 2"); // axis2.setAutoRangeIncludesZero(false); // subplot1.setRangeAxis(1, axis2); // subplot1.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // subplot1.setRenderer(1, new StandardXYItemRenderer()); // subplot1.mapDatasetToRangeAxis(1, 1); final XYTextAnnotation annotation1 = new XYTextAnnotation("x value", 20.0, 120000.0); final XYTextAnnotation annotation2 = new XYTextAnnotation("y value", 20.0, 110000.0); final XYTextAnnotation annotation3 = new XYTextAnnotation("z value", 20.0, 100000.0); final XYTextAnnotation annotation4 = new XYTextAnnotation("timepoint", 20.0, 10000.0); annotation1.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation2.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation3.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation4.setFont(new Font("SansSerif", Font.PLAIN, 9)); // annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation1); subplot1.addAnnotation(annotation2); subplot1.addAnnotation(annotation3); subplot1.addAnnotation(annotation4); // create subplot 2... final XYDataset data2 = createDataset2(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("Is this the title?", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.optaplanner.benchmark.impl.statistic.improvingsteppercentage.ImprovingStepPercentageProblemStatistic.java
@Override protected void writeGraphStatistic() { Map<Class<? extends Move>, XYPlot> plots = new HashMap<Class<? extends Move>, XYPlot>(); int seriesIndex = 0; for (SingleBenchmark singleBenchmark : problemBenchmark.getSingleBenchmarkList()) { Map<Class<? extends Move>, XYSeries> seriesMap = new HashMap<Class<? extends Move>, XYSeries>(); // No direct ascending lines between 2 points, but a stepping line instead XYItemRenderer renderer = new XYStepRenderer(); if (singleBenchmark.isSuccess()) { ImprovingStepPercentageSingleStatistic singleStatistic = (ImprovingStepPercentageSingleStatistic) singleBenchmark .getSingleStatistic(problemStatisticType); for (Map.Entry<Class<? extends Move>, List<ImprovingStepPercentageSingleStatisticPoint>> entry : singleStatistic .getPointLists().entrySet()) { Class<? extends Move> moveClass = entry.getKey(); if (!seriesMap.containsKey(moveClass)) { seriesMap.put(moveClass, new XYSeries(singleBenchmark.getSolverBenchmark().getNameWithFavoriteSuffix())); }//from w ww . j a v a 2 s.co m XYSeries series = seriesMap.get(moveClass); for (ImprovingStepPercentageSingleStatisticPoint point : entry.getValue()) { long timeMillisSpend = point.getTimeMillisSpend(); double ratio = point.getRatio(); series.add(timeMillisSpend, ratio); } } } if (singleBenchmark.getSolverBenchmark().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); } for (Map.Entry<Class<? extends Move>, XYSeries> entry : seriesMap.entrySet()) { Class<? extends Move> moveClass = entry.getKey(); if (!plots.containsKey(moveClass)) { plots.put(moveClass, createPlot(moveClass)); } plots.get(moveClass).setDataset(seriesIndex, new XYSeriesCollection(entry.getValue())); plots.get(moveClass).setRenderer(seriesIndex, renderer); } for (int i = 0; i < seriesMap.size(); i++) { } seriesIndex++; } graphStatisticFileMap = new LinkedHashMap<Class<? extends Move>, File>(plots.size()); for (Map.Entry<Class<? extends Move>, XYPlot> entry : plots.entrySet()) { Class<? extends Move> moveClass = entry.getKey(); JFreeChart chart = new JFreeChart(problemBenchmark.getName() + " improving step percentage " + moveClass.getSimpleName() + " statistic", JFreeChart.DEFAULT_TITLE_FONT, entry.getValue(), true); graphStatisticFileMap.put(moveClass, writeChartToImageFile(chart, problemBenchmark.getName() + "ImprovingStepPercentageStatistic-" + moveClass.getCanonicalName())); } }
From source file:com.sixrr.metrics.ui.charts.DiffHistogramDialog.java
private JFreeChart createChart(IntervalXYDataset dataset, boolean isIntegral) { final String title = getTitle(); final NumberAxis xAxis = new NumberAxis(); if (metricType.equals(MetricType.Ratio) || metricType.equals(MetricType.RecursiveRatio)) { xAxis.setNumberFormatOverride(new PercentFormatter()); }//from w w w . jav a 2 s . c o m if (isIntegral) { xAxis.setTickUnit(new NumberTickUnit(1.0)); } final XYToolTipGenerator tooltipGenerator = new StandardXYToolTipGenerator(); final XYItemRenderer renderer = new XYBarRenderer(); renderer.setToolTipGenerator(tooltipGenerator); renderer.setURLGenerator(null); final ValueAxis yAxis = new NumberAxis(); final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setRenderer(renderer); plot.setOrientation(PlotOrientation.VERTICAL); return new JFreeChart(title, JFreeChartConstants.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.squale.squaleweb.util.graph.KiviatMaker.java
/** * Create the JreeChart object/* ww w .j a v a 2 s . co m*/ * * @param showLegend indicate if it should display the legend or not * @param showBackground indicate if we want showBackground * @return The JreeChart object */ public JFreeChart getChart(boolean showLegend, boolean showBackground) { JFreeChart retChart = super.getChart(); // Creation of the graph if it not already exist if (null == retChart) { // Creation of the plot SpiderWebPlot plot = new SpiderWebPlot(mDataset); // Creation of the picture. The plot is inside the picture retChart = new JFreeChart(mTitle, TextTitle.DEFAULT_FONT, plot, false); // Display of the legend if (showLegend) { LegendTitle legendtitle = new LegendTitle(plot); legendtitle.setPosition(RectangleEdge.BOTTOM); retChart.addSubtitle(legendtitle); } // Definition of the style of the three first draw in the spiderWEbPlot. // This three first draw represent the scale for the mark 1.0, 2.0 and 3.0 in the plot // First we define the style final float miterLimit = 10.0f; final float[] dashPattern = { 5.0f, 3.0f }; BasicStroke dash = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, // End cap BasicStroke.JOIN_MITER, // Join style miterLimit, // Miter limit dashPattern, // Dash pattern 0.0f); // We associate this style to the draw plot.setSeriesPaint(0, new Color(WebMessages.getInt("kiviat.color.1"))); plot.setSeriesOutlineStroke(0, dash); plot.setSeriesPaint(1, new Color(WebMessages.getInt("kiviat.color.2"))); plot.setSeriesOutlineStroke(1, dash); plot.setSeriesPaint(2, new Color(WebMessages.getInt("kiviat.color.3"))); plot.setSeriesOutlineStroke(2, dash); // Define the gap what is draw and the border of the plot plot.setInteriorGap(DEFAULT_GAP); // Define the style of the line stroke plot.setBaseSeriesOutlineStroke(new BasicStroke(2.0f)); // The max value put in the plot (for the scale) plot.setMaxValue(SCALE_MAX_VALUE); // Indicate if we want fill the inner of the draw plot.setWebFilled(FILL_RADAR); if (!showBackground) { // Set the background of the picture to white retChart.setBackgroundPaint(Color.WHITE); // Set the border of the plot to white plot.setOutlinePaint(Color.WHITE); } super.setChart(retChart); } return retChart; }