@Override public void populate(XYPlot plot, AROTraceData analysis) { if (analysis != null) { gpsData.removeAllSeries(); // create the GPS dataset... Map<GpsState, XYIntervalSeries> seriesMap = new EnumMap<GpsState, XYIntervalSeries>(GpsState.class); for (GpsState eventType : GpsState.values()) { XYIntervalSeries series = new XYIntervalSeries(eventType); seriesMap.put(eventType, series); gpsData.addSeries(series); } Iterator<GpsInfo> iter = analysis.getAnalyzerResult().getTraceresult().getGpsInfos().iterator(); if (iter.hasNext()) { while (iter.hasNext()) { GpsInfo gpsEvent = iter.next(); if (gpsEvent.getGpsState() != GpsState.GPS_DISABLED) { seriesMap .get(gpsEvent.getGpsState()) .add( gpsEvent.getBeginTimeStamp(), gpsEvent.getBeginTimeStamp(), gpsEvent.getEndTimeStamp(), 0.5, 0, 1); } } } XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(gpsData.indexOf(GpsState.GPS_STANDBY), Color.YELLOW); renderer.setSeriesPaint(gpsData.indexOf(GpsState.GPS_ACTIVE), new Color(34, 177, 76)); // Assign ToolTip to renderer renderer.setBaseToolTipGenerator( new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { GpsState eventType = (GpsState) gpsData.getSeries(series).getKey(); return MessageFormat.format( ResourceBundleHelper.getMessageString("gps.tooltip"), dataset.getX(series, item), ResourceBundleHelper.getEnumString(eventType)); } }); } plot.setDataset(gpsData); }
public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) { HashMap<String, XYSeriesCollection> datasets = new HashMap<>(); for (int j = 0; j < games.size(); j++) { Game game = games.get(j); if (game == null) { continue; } for (String key : game.getVarData().keySet()) { if (datasets.containsKey(key)) { try { datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } catch (Exception e) { } } else { datasets.put(key, new XYSeriesCollection()); datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } } } HashMap<String, ChartPanel> chartPanels = new HashMap<>(); for (String key : datasets.keySet()) { JFreeChart chart = ChartFactory.createXYLineChart( key, // chart title "X", // x axis label "Y", // y axis label datasets.get(key), // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.size(); i++) { Game g = games.get(i); if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); chartPanels.put(key, chartPanel); } return chartPanels; }
public static void createGraphs(LinkedList<Game> games) { HashMap<String, XYSeriesCollection> datasets = new HashMap<>(); for (Game game : games) { for (String key : game.getVarData().keySet()) { if (datasets.containsKey(key)) { try { datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } catch (Exception e) { } } else { datasets.put(key, new XYSeriesCollection()); datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } } } for (String key : datasets.keySet()) { JFrame f = new JFrame(); JFreeChart chart = ChartFactory.createXYLineChart( key, // chart title "X", // x axis label "Y", // y axis label datasets.get(key), // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.size(); i++) { Game g = games.get(i); if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); f.setContentPane(chartPanel); f.pack(); RefineryUtilities.centerFrameOnScreen(f); f.setVisible(true); } }
public JFreeChart makegraph(Second g_start, Second g_end) { // read XYDataset readset = this.createread(); XYItemRenderer minichart1 = new StandardXYItemRenderer(); minichart1.setSeriesPaint(0, kSarConfig.color1); minichart1.setBaseStroke(kSarConfig.DEFAULT_STROKE); XYPlot subplot1 = new XYPlot(readset, null, new NumberAxis("Read"), minichart1); // writ XYDataset writset = this.createwrit(); XYItemRenderer minichart2 = new StandardXYItemRenderer(); minichart2.setSeriesPaint(0, kSarConfig.color2); minichart1.setSeriesPaint(1, kSarConfig.color3); minichart2.setBaseStroke(kSarConfig.DEFAULT_STROKE); XYPlot subplot2 = new XYPlot(writset, null, new NumberAxis("Write"), minichart2); // wcache XYDataset wcacheset = this.createwcache(); XYItemRenderer minichart3 = new StandardXYItemRenderer(); minichart3.setSeriesPaint(0, kSarConfig.color4); minichart3.setBaseStroke(kSarConfig.DEFAULT_STROKE); XYPlot subplot3 = new XYPlot(wcacheset, null, new NumberAxis("%wcache"), minichart3); // rcache XYDataset rcacheset = this.creatercache(); XYItemRenderer minichart4 = new StandardXYItemRenderer(); minichart4.setSeriesPaint(0, kSarConfig.color5); minichart4.setBaseStroke(kSarConfig.DEFAULT_STROKE); XYPlot subplot4 = new XYPlot(rcacheset, null, new NumberAxis("%rcache"), minichart4); // PANEL CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("")); plot.add(subplot1, 1); plot.add(subplot2, 1); plot.add(subplot3, 1); plot.add(subplot4, 1); plot.setOrientation(PlotOrientation.VERTICAL); JFreeChart mychart = new JFreeChart(this.getGraphTitle(), kSarConfig.DEFAULT_FONT, plot, true); if (setbackgroundimage(mychart) == 1) { subplot1.setBackgroundPaint(null); subplot2.setBackgroundPaint(null); subplot3.setBackgroundPaint(null); subplot4.setBackgroundPaint(null); } if (g_start != null) { DateAxis dateaxis1 = (DateAxis) mychart.getXYPlot().getDomainAxis(); dateaxis1.setRange(g_start.getStart(), g_end.getEnd()); } bufferrcachetrigger.setTriggerValue(kSarConfig.hpuxbufferrcachetrigger); bufferrcachetrigger.tagMarker(subplot4); return mychart; }
private static JFreeChart createChart(XYZDataset xyzdataset) { JFreeChart jfreechart = ChartFactory.createBubbleChart( "AGE vs WEIGHT vs WORK", "Weight (kg)", "AGE", xyzdataset, PlotOrientation.HORIZONTAL, true, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setForegroundAlpha(0.65F); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setSeriesPaint(0, Color.blue); NumberAxis numberaxis = (NumberAxis) xyplot.getDomainAxis(); numberaxis.setLowerMargin(0.2); numberaxis.setUpperMargin(0.5); NumberAxis numberaxis1 = (NumberAxis) xyplot.getRangeAxis(); numberaxis1.setLowerMargin(0.8); numberaxis1.setUpperMargin(0.9); return jfreechart; }
/** * @param games the games to graph * @param key the variable to create the graph with * @param start if index, the index at which to start, else the percent in the game at which to * start * @param stop if index, the index at which to end, else the percent in the game at which to end * @param index * @return */ public static ChartPanel getCustomGraph( Game[] games, String key, double start, double stop, boolean index) { XYSeriesCollection dataset = new XYSeriesCollection(); for (Game game : games) { ArrayList<Double> data = game.getVar(key); int begin; int end; if (index) { begin = (int) start; end = (int) stop; } else { begin = (int) (data.size() / start); end = (int) (data.size() / stop); } XYSeries series = GraphUtility.createSeries(data.subList(begin, end), "" + game.getId()); dataset.addSeries(series); } JFreeChart chart = ChartFactory.createXYLineChart( key, // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.length; i++) { Game g = games[i]; if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); return chartPanel; }
public GenericScatterGraph(XYSeries series, String xAxis, String yAxis) { super(); XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createScatterPlot( "", // chart title xAxis, // x axis label yAxis, // y axis label null, PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.darkGray); plot = chart.getXYPlot(); plot.setDataset(0, xyDataset); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); // Shape cross = ShapeUtilities.createDiamond(0.5f); Shape cross = ShapeUtilities.createDiagonalCross(0.5f, 0.5f); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, new Color(252, 141, 89)); renderer.setSeriesShape(0, cross); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setTickLabelPaint(Color.white); rangeAxis.setLabelPaint(Color.white); chartPanel = new ChartPanel(chart); chartPanel.setSize(100, 800); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); setBackground(Color.black); chartPanel.revalidate(); setVisible(true); }
/** * Create the charts * * @throws RemoteException On badness * @throws VisADException On badness */ public void loadData() throws VisADException, RemoteException { createChart(); List dataChoiceWrappers = getDataChoiceWrappers(); try { for (int dataSetIdx = 0; dataSetIdx < plot.getDatasetCount(); dataSetIdx++) { MyHistogramDataset dataset = (MyHistogramDataset) plot.getDataset(dataSetIdx); dataset.removeAllSeries(); } // dataset.removeAllSeries(); Hashtable props = new Hashtable(); props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE); for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) { DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx); DataChoice dataChoice = wrapper.getDataChoice(); FlatField data = getFlatField((FieldImpl) dataChoice.getData(null, props)); Unit unit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0]; double[][] samples = data.getValues(false); double[] actualValues = filterData(samples[0], getTimeValues(samples, data))[0]; NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit)); XYItemRenderer renderer; if (stacked) { renderer = new StackedXYBarRenderer(); } else { renderer = new XYBarRenderer(); } plot.setRenderer(paramIdx, renderer); Color c = wrapper.getColor(paramIdx); domainAxis.setLabelPaint(c); renderer.setSeriesPaint(0, c); MyHistogramDataset dataset = new MyHistogramDataset(); dataset.setType(HistogramType.FREQUENCY); dataset.addSeries(dataChoice.getName() + " [" + unit + "]", actualValues, bins); plot.setDomainAxis(paramIdx, domainAxis, false); plot.mapDatasetToDomainAxis(paramIdx, paramIdx); plot.setDataset(paramIdx, dataset); } } catch (Exception exc) { LogUtil.logException("Error creating data set", exc); return; } }
public void finish(java.awt.Dimension preferredSize) { ChartUtilities.applyCurrentTheme(chart); XYPlot plot = (XYPlot) chart.getPlot(); for (int i = 0; i < axisNum; i++) { XYItemRenderer renderer = plot.getRenderer(i); renderer.setSeriesPaint(0, colors[i]); ValueAxis axis = plot.getRangeAxis(i); axis.setLabelPaint(colors[i]); axis.setTickLabelPaint(colors[i]); } ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(preferredSize); chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(true); }
private JFreeChart createChart() { XYDataset xydataset = createDataset("Random 1", 100D, new Minute(), 200); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart( "Crosshair Demo 1", "Time of Day", "Value", xydataset, true, true, false); jfreechart.setBackgroundPaint(Color.white); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setOrientation(PlotOrientation.VERTICAL); xyplot.setBackgroundPaint(Color.lightGray); xyplot.setDomainGridlinePaint(Color.white); xyplot.setRangeGridlinePaint(Color.white); xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D)); xyplot.setDomainCrosshairVisible(true); xyplot.setDomainCrosshairLockedOnData(false); xyplot.setRangeCrosshairVisible(false); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); xyitemrenderer.setSeriesPaint(0, Color.black); return jfreechart; }
public JFreeChart makegraph(Second g_start, Second g_end) { // used XYDataset xydataset1 = this.createused(); XYPlot subplot1; NumberAxis usedaxis = new NumberAxis("% used cpu"); if (mysar.show100axiscpu) { usedaxis.setRange(0.0D, 100D); } if (mysar.showstackedcpu) { StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(); renderer.setSeriesPaint(0, kSarConfig.color1); renderer.setSeriesPaint(1, kSarConfig.color2); renderer.setSeriesPaint(2, kSarConfig.color3); renderer.setSeriesPaint(3, kSarConfig.color4); subplot1 = new XYPlot(stacked_used, new DateAxis(null), usedaxis, renderer); } else { XYItemRenderer minichart1 = new StandardXYItemRenderer(); minichart1.setBaseStroke(kSarConfig.DEFAULT_STROKE); minichart1.setSeriesPaint(0, kSarConfig.color1); minichart1.setSeriesPaint(1, kSarConfig.color2); minichart1.setSeriesPaint(2, kSarConfig.color3); minichart1.setSeriesPaint(2, kSarConfig.color4); subplot1 = new XYPlot(xydataset1, null, usedaxis, minichart1); } // idle XYDataset idleset = this.createidle(); XYItemRenderer minichart2 = new StandardXYItemRenderer(); minichart2.setSeriesPaint(0, kSarConfig.color5); minichart2.setBaseStroke(kSarConfig.DEFAULT_STROKE); XYPlot subplot2 = new XYPlot(idleset, null, new NumberAxis("% idle"), minichart2); // nice XYDataset niceset = this.createnice(); XYItemRenderer minichart3 = new StandardXYItemRenderer(); minichart3.setSeriesPaint(0, kSarConfig.color6); minichart3.setBaseStroke(kSarConfig.DEFAULT_STROKE); XYPlot subplot3 = new XYPlot(niceset, null, new NumberAxis("% niced"), minichart3); // the graph CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("")); plot.add(subplot1, 2); plot.add(subplot3, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // the graph JFreeChart mychart = new JFreeChart(this.getGraphTitle(), kSarConfig.DEFAULT_FONT, plot, true); if (g_start != null) { DateAxis dateaxis1 = (DateAxis) mychart.getXYPlot().getDomainAxis(); dateaxis1.setRange(g_start.getStart(), g_end.getEnd()); } if (setbackgroundimage(mychart) == 1) { subplot1.setBackgroundPaint(null); subplot2.setBackgroundPaint(null); subplot3.setBackgroundPaint(null); } // idle trigger cpuidletrigger.setTriggerValue(kSarConfig.linuxcpuidletrigger); cpuidletrigger.tagMarker(subplot2); // system trigger cpusystemtrigger.setTriggerValue(kSarConfig.linuxcpusystemtrigger); cpusystemtrigger.tagMarker(subplot1); // wio trigger if (cpuOpt.equals("%iowait") || cpuOpt.equals("%steal")) { cpuwiotrigger.setTriggerValue(kSarConfig.linuxcpuwiotrigger); cpuwiotrigger.tagMarker(subplot1); } // usr trigger cpuusrtrigger.setTriggerValue(kSarConfig.linuxcpuusrtrigger); cpuusrtrigger.tagMarker(subplot1); // return mychart; }
/** * Creates an overlaid chart. * * @return The chart. */ private static JFreeChart createCombinedChart() { // create plot ... IntervalXYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false); renderer1.setBaseToolTipGenerator( new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); renderer1.setSeriesStroke( 0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); renderer1.setSeriesPaint(0, Color.blue); DateAxis domainAxis = new DateAxis("Year"); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.02); ValueAxis rangeAxis = new NumberAxis("$billion"); XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); // add a second dataset and renderer... IntervalXYDataset data2 = createDataset2(); XYBarRenderer renderer2 = new XYBarRenderer() { public Paint getItemPaint(int series, int item) { XYDataset dataset = getPlot().getDataset(); if (dataset.getYValue(series, item) >= 0.0) { return Color.red; } else { return Color.green; } } }; renderer2.setSeriesPaint(0, Color.red); renderer2.setDrawBarOutline(false); renderer2.setBaseToolTipGenerator( new StandardXYToolTipGenerator( StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00"))); XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot cplot = new CombinedDomainXYPlot(domainAxis); cplot.add(plot1, 3); cplot.add(plot2, 2); cplot.setGap(8.0); cplot.setDomainGridlinePaint(Color.white); cplot.setDomainGridlinesVisible(true); cplot.setDomainPannable(true); // return a new chart containing the overlaid plot... JFreeChart chart = new JFreeChart("United States Public Debt", JFreeChart.DEFAULT_TITLE_FONT, cplot, false); TextTitle source = new TextTitle( "Source: http://www.publicdebt.treas.gov/opd/opdhisms.htm", new Font("Dialog", Font.PLAIN, 10)); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); LegendTitle legend = new LegendTitle(cplot); chart.addSubtitle(legend); ChartUtilities.applyCurrentTheme(chart); renderer2.setBarPainter(new StandardXYBarPainter()); renderer2.setShadowVisible(false); return chart; }
static JFreeChart createChart( NavigableMap<TimeAxisKey, DiffStat> aggregatedDiffstats, DiffStatConfiguration configuration) { boolean legend = false; boolean tooltips = false; boolean urls = false; Font helvetica = new Font("Helvetica", Font.PLAIN, 11 * configuration.multiplierInt()); XYDatasetMinMax datasetMinMax = createDeltaDataset("Additions and Delections", aggregatedDiffstats); XYDataset dataset = datasetMinMax.dataset; JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset, legend, tooltips, urls); chart.setBackgroundPaint(WHITE); chart.setBorderVisible(false); float strokeWidth = 1.2f * configuration.multiplierFloat(); XYPlot plot = chart.getXYPlot(); plot.setOrientation(VERTICAL); plot.setBackgroundPaint(WHITE); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(AXIS_LINE_COLOR); plot.setDomainGridlineStroke(new BasicStroke(1.0f * configuration.multiplierFloat())); plot.setRangeGridlinesVisible(false); plot.setOutlineVisible(false); DateAxis dateAxis = (DateAxis) plot.getDomainAxis(); dateAxis.setDateFormatOverride(new SimpleDateFormat("MM/yy")); dateAxis.setTickLabelFont(helvetica); dateAxis.setAxisLineVisible(false); dateAxis.setTickUnit(computeDateTickUnit(aggregatedDiffstats)); RectangleInsets insets = new RectangleInsets( 8.0d * configuration.multiplierDouble(), 4.0d * configuration.multiplierDouble(), 4.0d * configuration.multiplierDouble(), 4.0d * configuration.multiplierDouble()); dateAxis.setTickLabelInsets(insets); NumberAxis additionDeletionAxis = (NumberAxis) plot.getRangeAxis(0); additionDeletionAxis.setAxisLineVisible(false); additionDeletionAxis.setLabel("Additions and Deletions"); additionDeletionAxis.setLabelFont(helvetica); additionDeletionAxis.setTickLabelFont(helvetica); additionDeletionAxis.setRangeType(RangeType.FULL); int lowerBound = datasetMinMax.min + (int) (datasetMinMax.min * 0.1d); additionDeletionAxis.setLowerBound(lowerBound); int upperBound = datasetMinMax.max + (int) (datasetMinMax.max * 0.1d); additionDeletionAxis.setUpperBound(upperBound); additionDeletionAxis.setNumberFormatOverride(new AbbreviatingNumberFormat()); additionDeletionAxis.setMinorTickMarksVisible(false); additionDeletionAxis.setTickMarkInsideLength(5.0f * configuration.multiplierFloat()); additionDeletionAxis.setTickMarkOutsideLength(0.0f); additionDeletionAxis.setTickMarkStroke(new BasicStroke(2.0f * configuration.multiplierFloat())); additionDeletionAxis.setTickUnit( new NumberTickUnit(computeTickUnitSize(datasetMinMax.max + abs(datasetMinMax.min)))); XYAreaRenderer areaRenderer = new XYAreaRenderer(XYAreaRenderer.AREA); areaRenderer.setOutline(true); areaRenderer.setSeriesOutlinePaint(0, ADDED_STROKE); areaRenderer.setSeriesOutlineStroke(0, new BasicStroke(strokeWidth)); areaRenderer.setSeriesPaint(0, ADDED_FILL); areaRenderer.setSeriesOutlinePaint(1, REMOVED_STROKE); areaRenderer.setSeriesOutlineStroke(1, new BasicStroke(strokeWidth)); areaRenderer.setSeriesPaint(1, REMOVED_FILL); plot.setRenderer(0, areaRenderer); // Total Axis NumberAxis totalAxis = new NumberAxis("Total Lines"); totalAxis.setAxisLineVisible(false); totalAxis.setLabelPaint(VALUE_LABEL); totalAxis.setTickLabelPaint(TOTAL_LABEL); totalAxis.setLabelFont(helvetica); totalAxis.setTickLabelFont(helvetica); totalAxis.setNumberFormatOverride(new AbbreviatingNumberFormat()); totalAxis.setMinorTickMarksVisible(false); totalAxis.setTickMarkInsideLength(5.0f * configuration.multiplierFloat()); totalAxis.setTickMarkOutsideLength(0.0f); totalAxis.setTickMarkStroke(new BasicStroke(2.0f * configuration.multiplierFloat())); totalAxis.setTickMarkPaint(TOTAL_LABEL); plot.setRangeAxis(1, totalAxis); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); XYDatasetAndTotal datasetAndTotal = createTotalDataset("Total Lines", aggregatedDiffstats); XYDataset totalDataSet = datasetAndTotal.dataset; plot.setDataset(1, totalDataSet); plot.mapDatasetToRangeAxis(1, 1); // XYItemRenderer totalRenderer = new XYSplineRenderer(); XYItemRenderer totalRenderer = new StandardXYItemRenderer(); totalRenderer.setSeriesPaint(0, TOTAL_FILL); totalRenderer.setSeriesStroke( 0, new BasicStroke( strokeWidth, CAP_ROUND, JOIN_ROUND, 10.0f * configuration.multiplierFloat(), new float[] { 6.0f * configuration.multiplierFloat(), 3.0f * configuration.multiplierFloat() }, 0.0f)); plot.setRenderer(1, totalRenderer); totalAxis.setTickUnit(new NumberTickUnit(computeTickUnitSize(datasetAndTotal.total))); return chart; }
/** * @param axis Axis name to wich the new series belongs * @param cs Series Coinfiguration */ @Override public final void addSeries(String axis, SimpleSeriesConfiguration cs) { for (int i = 0; i < axes.size(); i++) { if (axes.get(i).getName().equals(axis)) { String strColor; javafx.scene.paint.Color color; int indice = seriesList.size(); if (cs.getColor() == null) { color = getColor(indice); } else { color = cs.getColor(); } strColor = color.toString(); XYSeriesCollection dataset = datasetList.get(i); Series series = new Series( cs.getName(), "color: " + strColor + ";width: " + String.valueOf(cs.getLineWidth()) + ";shape: " + cs.getShapeName() + ";", i, dataset.getSeriesCount()); dataset.addSeries(series); XYItemRenderer renderer = plot.getRenderer(i); renderer.setSeriesPaint(dataset.getSeriesCount() - 1, scene2awtColor(color)); SeriesShape simb = new SeriesShape( cs.getShapeName(), javafx.scene.paint.Color.web(strColor.replace("#", "0x"))); if (cs.getLineWidth() > 0) { ((XYLineAndShapeRenderer) renderer) .setSeriesLinesVisible(dataset.getSeriesCount() - 1, true); renderer.setSeriesStroke( dataset.getSeriesCount() - 1, new BasicStroke(cs.getLineWidth())); } else { ((XYLineAndShapeRenderer) renderer) .setSeriesLinesVisible(dataset.getSeriesCount() - 1, false); } if (cs.getShapeName().equals("null")) { renderer.setSeriesShape(dataset.getSeriesCount() - 1, null); ((XYLineAndShapeRenderer) renderer) .setSeriesShapesVisible(dataset.getSeriesCount() - 1, false); } else { renderer.setSeriesShape(dataset.getSeriesCount() - 1, simb.getShapeAWT()); ((XYLineAndShapeRenderer) renderer) .setSeriesShapesVisible(dataset.getSeriesCount() - 1, true); if (cs.getShapeName().contains("empty")) { ((XYLineAndShapeRenderer) renderer) .setSeriesShapesFilled(dataset.getSeriesCount() - 1, false); } else { ((XYLineAndShapeRenderer) renderer) .setSeriesShapesFilled(dataset.getSeriesCount() - 1, true); } } if (i == 0) { plot.setRenderer(renderer); } else { plot.setRenderer(i, renderer); } seriesList.add(series); final LegendAxis le = getLegendAxis(axis); final Label label = new Label(cs.toString()); Platform.runLater( () -> { label.setStyle( "fondo: " + strChartBackgroundColor + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: " + String.valueOf(fontSize) + "px"); }); label.setOnMouseClicked( (MouseEvent t) -> { if (t.getClickCount() == 2) { for (int i1 = 0; i1 < seriesList.size(); i1++) { if (seriesList.get(i1).getKey().toString().equals(label.getText())) { editSeries(seriesList.get(i1)); break; } } } }); label.setOnMouseExited( (MouseEvent t) -> { label.setStyle( label .getStyle() .replace("-fx-background-color: blue", "-fx-background-color: fondo")); }); label.setOnMouseEntered( (MouseEvent t) -> { label.setStyle( label .getStyle() .replace("-fx-background-color: fondo", "-fx-background-color: blue")); for (Node le1 : legendFrame.getChildren()) { if (le1 instanceof LegendAxis) { le1.setStyle("-fx-background-color:" + strBackgroundColor); ((LegendAxis) le1).selected = false; } } }); label.setStyle( "fondo: " + strChartBackgroundColor + ";-fx-text-fill: white;-fx-background-color: fondo;-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: " + String.valueOf(fontSize) + "px"); le.getChildren().add(label); label.setGraphic(simb.getShapeGraphic()); break; } } }
/** * Generates a chart in PNG format. * * @param outputFile the output file, it should exist. * @param pxWidth the image width in pixels. * @param pxHeight the image height in pixels. * @param chartTitle the chart title, may be null. * @param xAxisTitle the x axis title * @param yDataSeriesRange the axis range (null for auto) * @param yDataSeriesTitles the Y axis titles. * @param timeValuesInSeconds the time values in seconds * @param yDataSeries the Y axis value series. * @param yDataSeriesColors the Y axis value series drawing colors. * @param yDataSeriesTickSuffix TODO explain argument yDataSeriesTickSuffix * @param drawBorder draw, or not, the border. * @param backgroundColor the chart background color. */ final void generatePngChart( File outputFile, int pxWidth, int pxHeight, String chartTitle, String xAxisTitle, String[] yDataSeriesTitles, double[] timeValuesInSeconds, double[][] yDataSeriesRange, double[][] yDataSeries, Color[] yDataSeriesColors, String[] yDataSeriesTickSuffix, boolean drawBorder, Color backgroundColor) { // Domain axis NumberAxis xAxis = new NumberAxis(xAxisTitle); xAxis.setFixedDimension(CHART_AXIS_DIMENSION); xAxis.setLabelPaint(Color.black); xAxis.setTickLabelPaint(Color.black); double maxSeconds = getMaxValue(timeValuesInSeconds); TimeAxisResolution xAxisRes = TimeAxisResolution.findTimeUnit(maxSeconds); xAxis.setTickUnit(new NumberTickUnit(xAxisRes.tickStep)); double[] scaledTimeValues = xAxisRes.scale(timeValuesInSeconds); String tickSymbol = I18N.getString(locale, "running.job.details.chart.timeunit.symbol." + xAxisRes.name()); xAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + tickSymbol + "'")); // First dataset String firstDataSetTitle = yDataSeriesTitles[0]; XYDataset firstDataSet = createXYDataSet(firstDataSetTitle, scaledTimeValues, yDataSeries[0]); Color firstDataSetColor = yDataSeriesColors[0]; // First range axis NumberAxis firstYAxis = new NumberAxis(firstDataSetTitle); firstYAxis.setFixedDimension(CHART_AXIS_DIMENSION); setAxisRange(firstYAxis, yDataSeriesRange[0]); firstYAxis.setLabelPaint(firstDataSetColor); firstYAxis.setTickLabelPaint(firstDataSetColor); String firstAxisTickSuffix = yDataSeriesTickSuffix[0]; if (firstAxisTickSuffix != null && !firstAxisTickSuffix.isEmpty()) { firstYAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + firstAxisTickSuffix + "'")); } // Create the plot with domain axis and first range axis XYPlot plot = new XYPlot(firstDataSet, xAxis, firstYAxis, null); XYLineAndShapeRenderer firstRenderer = new XYLineAndShapeRenderer(true, false); plot.setRenderer(firstRenderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); firstRenderer.setSeriesPaint(0, firstDataSetColor); // Now iterate on next axes for (int i = 1; i < yDataSeries.length; i++) { // Create axis String seriesTitle = yDataSeriesTitles[i]; Color seriesColor = yDataSeriesColors[i]; NumberAxis yAxis = new NumberAxis(seriesTitle); yAxis.setFixedDimension(CHART_AXIS_DIMENSION); setAxisRange(yAxis, yDataSeriesRange[i]); yAxis.setLabelPaint(seriesColor); yAxis.setTickLabelPaint(seriesColor); String yAxisTickSuffix = yDataSeriesTickSuffix[i]; if (yAxisTickSuffix != null && !yAxisTickSuffix.isEmpty()) { yAxis.setNumberFormatOverride(new DecimalFormat("###.##'" + yAxisTickSuffix + "'")); } // Create dataset and add axis to plot plot.setRangeAxis(i, yAxis); plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_LEFT); plot.setDataset(i, createXYDataSet(seriesTitle, scaledTimeValues, yDataSeries[i])); plot.mapDatasetToRangeAxis(i, i); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, seriesColor); plot.setRenderer(i, renderer); } // Create the chart JFreeChart chart = new JFreeChart(chartTitle, JFreeChart.DEFAULT_TITLE_FONT, plot, false); // Customize rendering chart.setBackgroundPaint(Color.white); chart.setBorderVisible(true); chart.setBorderPaint(Color.BLACK); // Render image try { ChartUtilities.saveChartAsPNG(outputFile, chart, pxWidth, pxHeight); } catch (IOException e) { LOG.error("Chart export failed", e); } }
public void createGraph(final String filename, final TransitRoute route) { HashMap<Id, Integer> stopIndex = new HashMap<Id, Integer>(); int idx = 0; for (TransitRouteStop stop : route.getStops()) { stopIndex.put(stop.getStopFacility().getId(), idx); idx++; } HashSet<Id> vehicles = new HashSet<Id>(); for (Departure dep : route.getDepartures().values()) { vehicles.add(dep.getVehicleId()); } XYSeriesCollection dataset = new XYSeriesCollection(); int numSeries = 0; double earliestTime = Double.POSITIVE_INFINITY; double latestTime = Double.NEGATIVE_INFINITY; for (Map.Entry<Id, List<Tuple<Id, Double>>> entry : this.positions.entrySet()) { if (vehicles.contains(entry.getKey())) { XYSeries series = new XYSeries("t", false, true); for (Tuple<Id, Double> pos : entry.getValue()) { Integer stopIdx = stopIndex.get(pos.getFirst()); if (stopIdx != null) { double time = pos.getSecond().doubleValue(); series.add(stopIdx.intValue(), time); if (time < earliestTime) { earliestTime = time; } if (time > latestTime) { latestTime = time; } } } dataset.addSeries(series); numSeries++; } } JFreeChart c = ChartFactory.createXYLineChart( "Route-Time Diagram, Route = " + route.getId(), "stops", "time", dataset, PlotOrientation.VERTICAL, false, // legend? false, // tooltips? false // URLs? ); c.setBackgroundPaint(new Color(1.0f, 1.0f, 1.0f, 1.0f)); XYPlot p = (XYPlot) c.getPlot(); p.getRangeAxis().setInverted(true); p.getRangeAxis().setRange(earliestTime, latestTime); XYItemRenderer renderer = p.getRenderer(); for (int i = 0; i < numSeries; i++) { renderer.setSeriesPaint(i, Color.black); } try { ChartUtilities.saveChartAsPNG(new File(filename), c, 1024, 768, null, true, 9); } catch (IOException e) { e.printStackTrace(); } }