List of usage examples for org.jfree.chart.plot XYPlot XYPlot
public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer)
From source file:net.commerce.zocalo.freechart.ChartGenerator.java
public static JFreeChart createCustomXYStepAreaChart(TimePeriodValuesCollection top, TimePeriodValuesCollection bottom) { DateAxis xAxis = new DateAxis(null); NumberAxis yAxis = new NumberAxis("price"); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); yAxis.setUpperBound(100);//ww w. j av a 2s. com yAxis.setLowerBound(0.0); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setDataset(0, top); plot.setDataset(1, bottom); XYStepAreaRenderer bottomRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null); XYStepAreaRenderer topRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null); topRenderer.setRangeBase(1.0); topRenderer.setSeriesPaint(0, new Color(204, 255, 153)); bottomRenderer.setSeriesPaint(0, new Color(51, 255, 204)); plot.setRenderer(bottomRenderer); plot.setRenderer(1, topRenderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:org.optaplanner.benchmark.impl.statistic.single.constraintmatchtotalbestscore.ConstraintMatchTotalBestScoreSingleStatistic.java
private XYPlot createPlot(BenchmarkReport benchmarkReport, int scoreLevelIndex) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Constraint match total weight level " + scoreLevelIndex); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); return plot;//from w w w . j a v a 2s .co m }
From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java
private static JFreeChart createChart(final SecurityNode node) { Objects.requireNonNull(node); final List<SecurityHistoryNode> hNodes = node.getHistoryNodes(); final Date max = DateUtils.asDate(hNodes.get(hNodes.size() - 1).getLocalDate()); final Date min = DateUtils.asDate(hNodes.get(0).getLocalDate()); final DateAxis timeAxis = new DateAxis(null); timeAxis.setVisible(false);/*ww w.j a v a2 s .co m*/ timeAxis.setAutoRange(false); timeAxis.setRange(min, max); final NumberAxis valueAxis = new NumberAxis(null); valueAxis.setAutoRangeIncludesZero(false); valueAxis.setVisible(false); final XYAreaRenderer renderer = new XYAreaRenderer(); renderer.setBaseToolTipGenerator(new SecurityItemLabelGenerator(node)); renderer.setOutline(true); renderer.setSeriesPaint(0, new Color(225, 247, 223)); final XYPlot plot = new XYPlot(null, timeAxis, valueAxis, renderer); final List<List<SecurityHistoryNode>> groups = node.getHistoryNodeGroupsBySplits(); for (int i = 0; i < groups.size(); i++) { int size = groups.get(i).size(); Date[] date = new Date[size]; double[] high = new double[size]; double[] low = new double[size]; double[] open = new double[size]; double[] close = new double[size]; double[] volume = new double[size]; for (int j = 0; j < size; j++) { final SecurityHistoryNode hNode = groups.get(i).get(j); date[j] = DateUtils.asDate(hNode.getLocalDate()); high[j] = hNode.getAdjustedHigh().doubleValue(); low[j] = hNode.getAdjustedLow().doubleValue(); open[j] = hNode.getAdjustedPrice().doubleValue(); close[j] = hNode.getAdjustedPrice().doubleValue(); volume[j] = hNode.getVolume(); } final AbstractXYDataset data = new DefaultHighLowDataset(node.getDescription() + i, date, high, low, open, close, volume); plot.setDataset(i, data); } plot.setInsets(new RectangleInsets(1, 1, 1, 1)); final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(null); return chart; }
From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java
/** * * @param fragments//w ww. j a v a 2 s. com * @param ticvar * @param useRT * @return */ public XYPlot provide1DCoPlot(List<IFileFragment> fragments, String ticvar, boolean useRT) { final String satVar = "scan_acquisition_time"; DefaultXYZDataset cd = new DefaultXYZDataset(); int rowIdx = 0; double min = 0; double max = 1; double minRT = Double.POSITIVE_INFINITY; double maxRT = Double.NEGATIVE_INFINITY; int y = 0; for (IFileFragment f : fragments) { double[] domainValues = null; if (useRT) { domainValues = (double[]) f.getChild(satVar).getArray().get1DJavaArray(double.class); } else { domainValues = (double[]) f.getChild("scan_index").getArray().get1DJavaArray(double.class); } double[] tic = (double[]) f.getChild(ticvar).getArray().get1DJavaArray(double.class); double maxtic = MathTools.max(tic); double mintic = MathTools.min(tic); double[][] values = new double[3][tic.length]; for (int i = 0; i < tic.length; i++) { values[0][i] = domainValues[i]; values[1][i] = y; values[2][i] = Math.sqrt((tic[i] - mintic) / (maxtic - mintic)); } y++; cd.addSeries(f.getName(), values); } // ArrayDouble.D1 a = new ArrayDouble.D1(npoints); // int offset = 0; // for (IFileFragment f : t) { // Array tic = f.getChild(ticvar).getArray(); // int len = tic.getShape()[0]; // Array.arraycopy(tic, 0, a, offset, len); // offset += len; // } // histogram with fixed binsize // fill intensities into adequate bin, raise count in bin by one // afterwards, relative frequency within a bin gives a normalization // coefficient XYBlockRenderer xyb = new XYBlockRenderer(); GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), min, max, ImageTools.rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv"))); xyb.setPaintScale(ps); final String[] colnames = new String[fragments.size()]; for (int i = 0; i < colnames.length; i++) { colnames[i] = StringTools.removeFileExt(fragments.get(i).getName()); } NumberAxis na = null; if (useRT) { na = new NumberAxis("time [s]"); na.setAutoRangeIncludesZero(false); na.setLowerMargin(0); na.setUpperMargin(0); } else { na = new NumberAxis("scan index"); } // na.setVerticalTickLabels(true); XYPlot xyp = new XYPlot(cd, na, new SymbolAxis("chromatogram", colnames), xyb); xyb.setBlockWidth(1); xyp.setBackgroundPaint(Color.BLACK); xyb.setBaseToolTipGenerator(new XYZToolTipGenerator() { @Override public String generateToolTip(XYZDataset xyzd, int i, int i1) { return colnames[xyzd.getY(i, i1).intValue()] + " @" + xyzd.getXValue(i, i1) + " = " + xyzd.getZValue(i, i1); } @Override public String generateToolTip(XYDataset xyd, int i, int i1) { if (xyd instanceof XYZDataset) { return generateToolTip((XYZDataset) xyd, i, i1); } return colnames[xyd.getY(i, i1).intValue()] + ":" + xyd.getXValue(i, i1); } }); return xyp; }
From source file:com.joliciel.jochre.graphics.SourceImageImpl.java
private void drawChart(int[] pixelSpread, DescriptiveStatistics countStats, DescriptiveStatistics blackCountStats, DescriptiveStatistics blackSpread, int startWhite, int endWhite, int startBlack, int blackThresholdValue) { XYSeries xySeries = new XYSeries("Brightness data"); double maxSpread = 0; for (int i = 0; i < 256; i++) { xySeries.add(i, pixelSpread[i]); if (pixelSpread[i] > maxSpread) maxSpread = pixelSpread[i];//from w w w. j av a 2 s . com } XYSeries keyValues = new XYSeries("Key values"); XYSeries counts = new XYSeries("Counts"); counts.add(10.0, countStats.getMean()); counts.add(100.0, blackCountStats.getMean()); counts.add(125.0, blackCountStats.getMean() + (1.0 * blackCountStats.getStandardDeviation())); counts.add(150.0, blackCountStats.getMean() + (2.0 * blackCountStats.getStandardDeviation())); counts.add(175.0, blackCountStats.getMean() + (3.0 * blackCountStats.getStandardDeviation())); counts.add(75.0, blackCountStats.getMean() - (1.0 * blackCountStats.getStandardDeviation())); counts.add(50.0, blackCountStats.getMean() - (2.0 * blackCountStats.getStandardDeviation())); counts.add(25.0, blackCountStats.getMean() - (3.0 * blackCountStats.getStandardDeviation())); keyValues.add(startWhite, maxSpread / 4.0); keyValues.add(endWhite, maxSpread / 4.0); keyValues.add(startBlack, maxSpread / 4.0); keyValues.add(blackThresholdValue, maxSpread / 2.0); XYSeriesCollection dataset = new XYSeriesCollection(xySeries); dataset.addSeries(keyValues); dataset.addSeries(counts); final ValueAxis xAxis = new NumberAxis("Brightness"); final ValueAxis yAxis = new NumberAxis("Count"); yAxis.setUpperBound(maxSpread); xAxis.setUpperBound(255.0); //final XYItemRenderer renderer = new XYBarRenderer(); final XYBarRenderer renderer = new XYBarRenderer(); renderer.setShadowVisible(false); final XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.VERTICAL); String title = "BrightnessChart"; final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(Color.white); File file = new File("data/" + title + ".png"); try { ChartUtilities.saveChartAsPNG(file, chart, 600, 600); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:projects.upc.exec.HrDiagram.java
/** * Update the {@link HrDiagram#chartPanel}. *///from w w w . jav a 2s . c o m private void updateChart() { XYSeries series = new XYSeries("UPC HR diagram"); for (Entry<UpcStar, SsaCrossMatch> xm : starsToPlot.entrySet()) { UpcStar upcStar = xm.getKey(); SsaCrossMatch ssa = xm.getValue(); // Get the SSA colours of the UPC star double b = ssa.ssaB; double r2 = ssa.ssaR2; // double i = ssa.ssaI; // Use the parallax to correct the apparent magnitude to absolute magnitude. // Extract the parallax and error to use double p = (useHip && upcStar.isHipparcosStar()) ? upcStar.srcPi : upcStar.absPi; double sigma_p = (useHip && upcStar.isHipparcosStar()) ? upcStar.srcPiErr : upcStar.absPiErr; // Filter on the fractional parallax error double f = sigma_p / p; if (f > fMax) { continue; } // Correct to arcseconds p /= 1000; sigma_p /= 1000; // Get the distance double d = DistanceFromParallax.getDistance(p, sigma_p, method); // Filter & convert to absolute magnitude if (d > 0 && !Double.isInfinite(d)) { double B = MagnitudeUtils.getAbsoluteMagnitude(d, b); series.add(b - r2, B); } } XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(series); // Set up the renderer XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1)); // Configure axes NumberAxis xAxis = new NumberAxis("B - R [mag]"); xAxis.setRange(-1.0, 3.5); NumberAxis yAxis = new NumberAxis("B [mag]"); yAxis.setInverted(true); yAxis.setRange(-5, 15); // Configure plot XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer); xyplot.setBackgroundPaint(Color.white); JFreeChart chart = new JFreeChart("HR diagram of UPC stars with SSA cross-matches", xyplot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); if (chartPanel == null) { // Branch is used on initialisation chartPanel = new ChartPanel(chart); } else { chartPanel.setChart(chart); } }
From source file:cs.gui.stats.PerformanceStats.java
private ChartPanel createChart(String axisLabel, int type) { int width = (screenSize.width - (screenSize.width / 35)); int height = (int) (screenSize.height - (screenSize.height / (double) 4)); //int width = (screenSize.width - (screenSize.width / 35)) / 2; //int height = (int) (screenSize.height - (screenSize.height / (double) 4)) / 2; lastValue = new double[SUBPLOT_COUNT]; //================= visualise standard chart ========================== CombinedDomainXYPlot combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time")); lastValue[0] = 100D;/* ww w.j a va 2 s.c om*/ TimeSeries timeseries = null; XYPlot xyplot = null; //add new timeseries to modularity row datasets[type] = new TimeSeriesCollection(); NumberAxis numberaxis = new NumberAxis(axisLabel); numberaxis.setAutoRangeIncludesZero(true); //fast StandardXYItemRenderer xyItemRender = new StandardXYItemRenderer(); //original //xyItemRender = new StandardXYItemRenderer(); xyItemRender.setSeriesStroke(0, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(1, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(2, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); xyItemRender.setSeriesStroke(3, new BasicStroke(lineThickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0, null, 0)); //TODO colours need to be defined statically before the renderer is created! xyplot = new XYPlot(datasets[type], null, numberaxis, xyItemRender); switch (type) { case 0: { xyItemRender.setSeriesPaint(0, Color.BLACK); timeseries = new TimeSeries("Number of existing threads", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); timeseries = new TimeSeries("Number of answered threads", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 1: { xyItemRender.setSeriesPaint(0, Color.YELLOW); timeseries = new TimeSeries("Mean thread answer time (per day)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 2: { xyItemRender.setSeriesPaint(0, Color.GRAY); timeseries = new TimeSeries("Number of thread replies", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 3: { xyItemRender.setSeriesPaint(0, Color.GREEN); timeseries = new TimeSeries("New thread arrival activity change (%)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); xyItemRender.setSeriesPaint(1, Color.BLUE); timeseries = new TimeSeries("Thread reply activity change (%)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; case 4: { xyItemRender.setSeriesPaint(0, Color.GREEN); timeseries = new TimeSeries("Mean thread aswer time (per month)", org.jfree.data.time.Hour.class); datasets[type].addSeries(timeseries); } break; } NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.add(xyplot); ChartPanel chart = null; switch (type) { case 0: { jfreechart1 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart1.getSubtitle(0); //set legend fonts jfreechart1.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart1.setBorderPaint(Color.black); jfreechart1.setBorderVisible(true); jfreechart1.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis1 = combineddomainxyplot.getDomainAxis(); dateAxis1 = (DateAxis) valueAxis1; if (scope1 == 0) { valueAxis1.setAutoRange(true); } else { valueAxis1.setFixedAutoRange(scope1); } chart = new ChartPanel(jfreechart1); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis1, dateAxis1, ddlScope1)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart1.setAntiAlias(false); } break; case 1: { jfreechart2 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart2.getSubtitle(0); //set legend fonts jfreechart2.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart2.setBorderPaint(Color.black); jfreechart2.setBorderVisible(true); jfreechart2.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis2 = combineddomainxyplot.getDomainAxis(); dateAxis2 = (DateAxis) valueAxis2; if (scope2 == 0) { valueAxis2.setAutoRange(true); } else { valueAxis2.setFixedAutoRange(scope2); } chart = new ChartPanel(jfreechart2); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis2, dateAxis2, ddlScope2)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart2.setAntiAlias(false); } break; case 2: { jfreechart3 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart3.getSubtitle(0); //set legend fonts jfreechart3.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart3.setBorderPaint(Color.black); jfreechart3.setBorderVisible(true); jfreechart3.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis3 = combineddomainxyplot.getDomainAxis(); dateAxis3 = (DateAxis) valueAxis3; if (scope3 == 0) { valueAxis3.setAutoRange(true); } else { valueAxis3.setFixedAutoRange(scope3); } chart = new ChartPanel(jfreechart3); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis3, dateAxis3, ddlScope3)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart3.setAntiAlias(false); } break; case 3: { jfreechart4 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart4.getSubtitle(0); //set legend fonts jfreechart4.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart4.setBorderPaint(Color.black); jfreechart4.setBorderVisible(true); jfreechart4.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis4 = combineddomainxyplot.getDomainAxis(); dateAxis4 = (DateAxis) valueAxis4; if (scope4 == 0) { valueAxis4.setAutoRange(true); } else { valueAxis4.setFixedAutoRange(scope4); } chart = new ChartPanel(jfreechart4); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis4, dateAxis4, ddlScope4)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart4.setAntiAlias(false); } break; case 4: { jfreechart5 = new JFreeChart("", combineddomainxyplot); LegendTitle legendtitle = (LegendTitle) jfreechart5.getSubtitle(0); //set legend fonts jfreechart5.getLegend(0).setItemFont(new Font("Italic", Font.PLAIN, 11)); legendtitle.setPosition(RectangleEdge.BOTTOM); legendtitle.setMargin(new RectangleInsets(UnitType.ABSOLUTE, 0.0D, 4D, 0.0D, 4D)); jfreechart5.setBorderPaint(Color.black); jfreechart5.setBorderVisible(true); jfreechart5.setBackgroundPaint(Color.white); combineddomainxyplot.setBackgroundPaint(Color.lightGray); combineddomainxyplot.setDomainGridlinePaint(Color.white); combineddomainxyplot.setRangeGridlinePaint(Color.white); combineddomainxyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); valueAxis5 = combineddomainxyplot.getDomainAxis(); dateAxis5 = (DateAxis) valueAxis5; if (scope5 == 0) { valueAxis5.setAutoRange(true); } else { valueAxis5.setFixedAutoRange(scope5); } chart = new ChartPanel(jfreechart5); chart.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); chart.add(buildPlotDisplayManagementPanel(valueAxis5, dateAxis5, ddlScope5)); combineddomainxyplot.setInsets(new RectangleInsets(40, 25, 0, 10)); chart.setPreferredSize(new Dimension(width, height)); jfreechart5.setAntiAlias(false); } break; } return chart; }
From source file:org.jivesoftware.openfire.reporting.graph.GraphEngine.java
/** * Generates a Chart.//from www.j a v a2 s .c o m * * @param title the title of the chart. * @param data the data to use in the chart. * @param xAxis the variables to use on the xAxis. * @param yAxis the variables to use on the yAxis. * @param orientation the orientation * @param itemRenderer the type of renderer to use. * @return the generated chart. */ private JFreeChart createChart(String title, XYDataset data, ValueAxis xAxis, ValueAxis yAxis, PlotOrientation orientation, XYItemRenderer itemRenderer, GraphDefinition def) { int seriesCount = data.getSeriesCount(); for (int i = 0; i < seriesCount; i++) { itemRenderer.setSeriesPaint(i, def.getInlineColor(i)); itemRenderer.setSeriesOutlinePaint(i, def.getOutlineColor(i)); } XYPlot plot = new XYPlot(data, xAxis, yAxis, null); plot.setOrientation(orientation); plot.setRenderer(itemRenderer); return createChart(title, plot); }
From source file:AtomPanel.java
private void initJFreeChart() { this.numOfStream = numOfStream; datasets = new TimeSeriesCollection(); trend = new TimeSeriesCollection(); projpcs = new TimeSeriesCollection(); spe = new TimeSeriesCollection(); for (int i = 0; i < MaxNumOfStream; i++) { //add streams TimeSeries timeseries = new TimeSeries("Stream " + i, Millisecond.class); datasets.addSeries(timeseries);/* ww w. j a v a2 s . co m*/ timeseries.setHistoryCount(historyRange); //add trend variables TimeSeries trendSeries = new TimeSeries("Trend " + i, Millisecond.class); trend.addSeries(trendSeries); trendSeries.setHistoryCount(historyRange); //add proj onto PCs variables TimeSeries PC = new TimeSeries("Projpcs " + i, Millisecond.class); projpcs.addSeries(PC); PC.setHistoryCount(historyRange); //add spe streams TimeSeries speSeries = new TimeSeries("Spe " + i, Millisecond.class); spe.addSeries(speSeries); speSeries.setHistoryCount(historyRange); } combineddomainxyplot = new CombinedDomainXYPlot(new DateAxis("Time")); //data stream plot DateAxis domain = new DateAxis("Time"); NumberAxis range = new NumberAxis("Streams"); 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 DefaultXYItemRenderer(); renderer.setItemLabelsVisible(false); renderer.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); XYPlot plot = new XYPlot(datasets, domain, range, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 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()); combineddomainxyplot.add(plot); //Trend captured by pca DateAxis domain0 = new DateAxis("Time"); NumberAxis range0 = new NumberAxis("PCA Trend"); domain0.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range0.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain0.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range0.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); XYItemRenderer renderer0 = new DefaultXYItemRenderer(); renderer0.setItemLabelsVisible(false); renderer0.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer0.setSeriesPaint(0, Color.blue); renderer0.setSeriesPaint(1, Color.red); renderer0.setSeriesPaint(2, Color.magenta); XYPlot plot0 = new XYPlot(trend, domain0, range0, renderer0); plot0.setBackgroundPaint(Color.lightGray); plot0.setDomainGridlinePaint(Color.white); plot0.setRangeGridlinePaint(Color.white); plot0.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); domain0.setAutoRange(true); domain0.setLowerMargin(0.0); domain0.setUpperMargin(0.0); domain0.setTickLabelsVisible(false); range0.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); combineddomainxyplot.add(plot0); //proj on PCs plot DateAxis domain1 = new DateAxis("Time"); NumberAxis range1 = new NumberAxis("Proj on PCs"); domain1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain1.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range1.setLabelFont(new Font("SansSerif", Font.PLAIN, 12)); XYItemRenderer renderer1 = new DefaultXYItemRenderer(); renderer1.setItemLabelsVisible(false); renderer1.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.blue); renderer1.setSeriesPaint(1, Color.red); renderer1.setSeriesPaint(2, Color.magenta); plot1 = new XYPlot(projpcs, domain1, range1, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); plot1.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); domain1.setAutoRange(true); domain1.setLowerMargin(0.0); domain1.setUpperMargin(0.0); domain1.setTickLabelsVisible(false); range1.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); combineddomainxyplot.add(plot1); //spe plot DateAxis domain2 = new DateAxis("Time"); NumberAxis range2 = new NumberAxis("SPE"); domain2.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); range2.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); domain2.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); range2.setLabelFont(new Font("SansSerif", Font.PLAIN, 14)); XYItemRenderer renderer2 = new DefaultXYItemRenderer(); renderer2.setItemLabelsVisible(false); renderer2.setStroke(new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); XYPlot plot2 = new XYPlot(spe, domain2, range2, renderer); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); plot2.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); domain2.setAutoRange(true); domain2.setLowerMargin(0.0); domain2.setUpperMargin(0.0); domain2.setTickLabelsVisible(true); range2.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); combineddomainxyplot.add(plot2); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(historyRange); // 60 seconds JFreeChart chart; if (this.pcaType == AtomUtils.PCAType.pca) chart = new JFreeChart("CloudWatch-ATOM with Exact Data", new Font("SansSerif", Font.BOLD, 18), combineddomainxyplot, false); else if (this.pcaType == AtomUtils.PCAType.pcaTrack) chart = new JFreeChart("CloudWatch-ATOM with Fixed Tracking Threshold", new Font("SansSerif", Font.BOLD, 18), combineddomainxyplot, false); else chart = new JFreeChart("CloudWatch-ATOM with Dynamic Tracking Threshold", new Font("SansSerif", Font.BOLD, 18), combineddomainxyplot, false); chart.setBackgroundPaint(Color.white); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createLineBorder(Color.black))); AtomPanel.this.add(chartPanel, BorderLayout.CENTER); }
From source file:ch.agent.crnickl.demo.stox.Chart.java
private XYPlot getLinePlot() throws KeyedException { // use a number axis on the left side (default) NumberAxis axis = new NumberAxis(); axis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(null, null, axis, null); return plot;//w ww . j av a2 s .co m }