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 createOverlaidOHLCAndStepChart(TimePeriodValuesCollection bottom, TimePeriodValuesCollection top, OHLCDataset ohlCdata) { DateAxis xAxis = new DateAxis(null); NumberAxis yAxis = new NumberAxis("price"); yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); yAxis.setUpperBound(100);/*from w w w .ja v a 2 s . c o m*/ yAxis.setLowerBound(0.0); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setDataset(0, bottom); plot.setDataset(1, top); plot.setDataset(2, ohlCdata); XYStepAreaRenderer bottomRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null); XYStepAreaRenderer topRenderer = new XYStepAreaRenderer(XYStepAreaRenderer.AREA, null, null); HighLowRenderer hiLoRenderer = new HighLowRenderer(); 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.setRenderer(2, hiLoRenderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java
/** * Creates a chart for the specified dataset. * //from w w w .ja v a2s . c o m * @param dataset the dataset. * * @return A chart instance. */ public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); XYZDataset dataset = (XYZDataset) datasets.getDatasets().get("1"); JFreeChart chart = null; NumberAxis xAxis = new NumberAxis(xLabel); xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (xLowerBound != null && xUpperBound != null) { xAxis.setLowerBound(xLowerBound); xAxis.setUpperBound(xUpperBound); } else { xAxis.setAutoRange(true); } xAxis.setAxisLinePaint(Color.white); xAxis.setTickMarkPaint(Color.white); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { xAxis.setLabelFont(addLabelsStyle.getFont()); xAxis.setLabelPaint(addLabelsStyle.getColor()); } NumberAxis yAxis = new NumberAxis(yLabel); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); if (yLowerBound != null && yUpperBound != null) { yAxis.setLowerBound(yLowerBound); yAxis.setUpperBound(yUpperBound); } else yAxis.setAutoRange(true); yAxis.setAxisLinePaint(Color.white); yAxis.setTickMarkPaint(Color.white); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { yAxis.setLabelFont(addLabelsStyle.getFont()); yAxis.setLabelPaint(addLabelsStyle.getColor()); } XYBlockRenderer renderer = new XYBlockRenderer(); PaintScale paintScale = null; if (grayPaintScale) { paintScale = new GrayPaintScale(minScaleValue, maxScaleValue); } else { if (scaleLowerBound != null && scaleUpperBound != null) { paintScale = new LookupPaintScale(scaleLowerBound, scaleUpperBound, Color.gray); } else { paintScale = new LookupPaintScale(minScaleValue, maxScaleValue, Color.gray); } for (int i = 0; i < zRangeArray.length; i++) { ZRange zRange = zRangeArray[i]; ((LookupPaintScale) paintScale).add(zRange.getValue().doubleValue(), zRange.getColor()); } } renderer.setPaintScale(paintScale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); plot.setForegroundAlpha(0.66f); chart = new JFreeChart(plot); TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } chart.removeLegend(); NumberAxis scaleAxis = new NumberAxis(zLabel); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7)); if (scaleLowerBound != null && scaleUpperBound != null) { scaleAxis.setLowerBound(scaleLowerBound); scaleAxis.setUpperBound(scaleUpperBound); } else scaleAxis.setAutoRange(true); if (addLabelsStyle != null && addLabelsStyle.getFont() != null) { scaleAxis.setLabelFont(addLabelsStyle.getFont()); scaleAxis.setLabelPaint(addLabelsStyle.getColor()); } if (blockHeight != null && blockWidth != null) { renderer.setBlockWidth(blockWidth.doubleValue()); renderer.setBlockHeight(blockHeight.doubleValue()); } PaintScaleLegend legend = new PaintScaleLegend(paintScale, scaleAxis); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5.0); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setFrame(new BlockBorder(Color.black)); legend.setPadding(new RectangleInsets(10, 10, 10, 10)); legend.setStripWidth(10); legend.setPosition(RectangleEdge.RIGHT); legend.setBackgroundPaint(color); chart.addSubtitle(legend); // chart.setBackgroundPaint(new Color(180, 180, 250)); chart.setBackgroundPaint(color); logger.debug("OUT"); return chart; }
From source file:asl.util.PlotMaker.java
public void plotPSD(double per[], double[] model, double[] nhnmPer, double[] nhnm, double[] psd, String modelName, String plotString) { // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png" final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format(/*from w w w . jav a 2s . c o m*/ "== plotPSD: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return; } Boolean plotNHNM = false; //if (nhnm.length > 0) { if (nhnm != null) { plotNHNM = true; } final XYSeries series1 = new XYSeries(modelName); final XYSeries series2 = new XYSeries(channel.toString()); final XYSeries series3 = new XYSeries("NHNM"); for (int k = 0; k < per.length; k++) { series1.add(per[k], model[k]); series2.add(per[k], psd[k]); } if (plotNHNM) { for (int k = 0; k < nhnmPer.length; k++) { series3.add(nhnmPer[k], nhnm[k]); } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShape(2, rectangle); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesLinesVisible(2, true); Paint[] paints = new Paint[] { Color.blue, Color.red, Color.black }; renderer.setSeriesPaint(0, paints[0]); renderer.setSeriesPaint(1, paints[1]); renderer.setSeriesPaint(2, paints[2]); final NumberAxis rangeAxis1 = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB"); //rangeAxis1.setRange( new Range(-190, -120)); rangeAxis1.setRange(new Range(-190, -95)); rangeAxis1.setTickUnit(new NumberTickUnit(5.0)); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(0.05, 10000)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); seriesCollection.addSeries(series2); if (plotNHNM) { seriesCollection.addSeries(series3); } final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, rangeAxis1, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final JFreeChart chart = new JFreeChart(xyplot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:org.jfree.chart.demo.SymbolicYPlotDemo.java
/** * Displays a vertically combined symbolic plot. * //from ww w. java 2 s . co m * @param frameTitle * the frame title. * @param data1 * dataset 1. * @param data2 * dataset 2. */ private static void displayYSymbolicCombinedVertically(final String frameTitle, final SampleYSymbolicDataset data1, final SampleYSymbolicDataset data2) { final String title = "Animals Vertically Combined"; final String xAxisLabel = "Miles"; final String yAxisLabel = null; // create master dataset... final CombinedDataset data = new CombinedDataset(); data.add(data1); data.add(data2); // decompose data... final XYDataset series0 = new SubSeriesDataset(data, 0); final XYDataset series1 = new SubSeriesDataset(data, 1); final XYDataset series2 = new SubSeriesDataset(data, 2); final XYDataset series3 = new SubSeriesDataset(data, 3); final XYDataset series4 = new SubSeriesDataset(data, 4); final XYDataset series5 = new SubSeriesDataset(data, 5); final XYDataset series6 = new SubSeriesDataset(data, 6); final XYDataset series7 = new SubSeriesDataset(data, 7); // common horizontal and vertical axes final ValueAxis valueAxis = new NumberAxis(xAxisLabel); final SymbolicAxis symbolicAxis1 = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data1).getYSymbolicValues()); final SymbolicAxis symbolicAxis2 = new SymbolicAxis(yAxisLabel, ((YisSymbolic) data2).getYSymbolicValues()); // create the main plot... final CombinedDomainXYPlot mainPlot = new CombinedDomainXYPlot(valueAxis); // and the sub-plots... final XYItemRenderer renderer0 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot subplot0 = new XYPlot(series0, null, symbolicAxis1, renderer0); final XYItemRenderer renderer1 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot subplot1 = new XYPlot(series1, null, symbolicAxis1, renderer1); final XYItemRenderer renderer2 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot subplot2 = new XYPlot(series2, null, symbolicAxis1, renderer2); final XYItemRenderer renderer3 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot subplot3 = new XYPlot(series3, null, symbolicAxis1, renderer3); final XYItemRenderer renderer4 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot subplot4 = new XYPlot(series4, null, symbolicAxis2, renderer4); final XYItemRenderer renderer5 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot subplot5 = new XYPlot(series5, null, symbolicAxis2, renderer5); final XYItemRenderer renderer6 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot subplot6 = new XYPlot(series6, null, symbolicAxis2, renderer6); final XYItemRenderer renderer7 = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES, null); final XYPlot subplot7 = new XYPlot(series7, null, symbolicAxis2, renderer7); // add the subplots to the main plot... mainPlot.add(subplot0, 1); mainPlot.add(subplot1, 1); mainPlot.add(subplot2, 1); mainPlot.add(subplot3, 1); mainPlot.add(subplot4, 1); mainPlot.add(subplot5, 1); mainPlot.add(subplot6, 1); mainPlot.add(subplot7, 1); // construct the chart... final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); // and present it in a frame... final JFrame frame = new ChartFrame(frameTitle, chart); frame.pack(); RefineryUtilities.positionFrameRandomly(frame); frame.show(); }
From source file:com.att.aro.main.PacketPlots.java
/** * The utility method that creates the packet plots from a packet series map */// w ww.j a va2 s. c o m private XYPlot createPlot() { // Create the plot renderer YIntervalRenderer renderer = new YIntervalRenderer() { private static final long serialVersionUID = 1L; public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset; double x = intervalDataset.getXValue(series, item); double yLow = intervalDataset.getStartYValue(series, item); double yHigh = intervalDataset.getEndYValue(series, item); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation); double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation); double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation); Paint p = getItemPaint(series, item); Stroke s = getItemStroke(series, item); Line2D line = null; PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(yyLow, xx, yyHigh, xx); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(xx, yyLow, xx, yyHigh); } g2.setPaint(p); g2.setStroke(s); g2.draw(line); // add an entity for the item... if (entities != null) { if (entityArea == null) { entityArea = line.getBounds(); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } XYItemEntity entity = new XYItemEntity(entityArea, dataset, series, item, tip, null); entities.add(entity); } } }; renderer.setAdditionalItemLabelGenerator(null); renderer.setBaseShape(new Rectangle()); renderer.setAutoPopulateSeriesShape(false); renderer.setAutoPopulateSeriesPaint(false); renderer.setBasePaint(Color.GRAY); // Create the plot XYPlot plot = new XYPlot(null, null, new NumberAxis(), renderer); plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); plot.getRangeAxis().setVisible(false); return plot; }
From source file:graficos.Grafico1.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed ChartPanel panel;// w w w. ja v a2s. c o m JFreeChart chart = null; if (l.isSelected()) { //Grafico de Linea int ban = 1; //para validar que la tabla no esta vacia o que tenga solo caracteres numericos XYSplineRenderer renderer = new XYSplineRenderer();// renderizador XYSeriesCollection dataset = new XYSeriesCollection();// variable para almacenar los datos que le enviamos para hacer el ploteo //Ejes x , y ValueAxis x = new NumberAxis(); ValueAxis y = new NumberAxis(); XYSeries serie = new XYSeries("Datos");//almacena conjunto de datos que vamos a graficar //Le paso por parametro el nombre que recibe la serie XYPlot plot; // Hago el recorrido del JTable datos y lo agrego a la serie try { for (int fila = 0; fila < 5; fila++) { GraficoLinea.removeAll(); serie.add(Float.parseFloat(String.valueOf(datos.getValueAt(fila, 0))), Float.parseFloat(String.valueOf(datos.getValueAt(fila, 1)))); } } catch (Exception e) { ban = 0; JOptionPane.showMessageDialog(this, e.toString()); } if (ban == 1) { // Pasos claves para hacer el grafico de linea // Agrego al dataset la serie de datos. dataset.addSeries(serie); //Nombres de los ejes x.setLabel("Eje X"); y.setLabel("Eje Y"); //Ploteo pasando por parametr , el data set, los ejes y el renderer. plot = new XYPlot(dataset, x, y, renderer); chart = new JFreeChart(plot); chart.setTitle("Grafico de Lineas"); } } else { if (b.isSelected()) { //Grafico de Barra DefaultCategoryDataset data = new DefaultCategoryDataset(); // este esta hecho con datos que yo invente.. String producto1 = "Sopa Quick"; String producto2 = "Yerba Mate"; String dia1 = "Dia 1"; String dia2 = "Dia 2"; String dia3 = "Dia 3"; String dia4 = "Dia 4"; String dia5 = "Dia 5"; data.addValue(14, dia1, producto1); data.addValue(17, dia2, producto1); data.addValue(19, dia3, producto1); data.addValue(27, dia4, producto1); data.addValue(30, dia5, producto1); data.addValue(1, dia1, producto2); data.addValue(4, dia2, producto2); data.addValue(9, dia3, producto2); data.addValue(16, dia4, producto2); data.addValue(33, dia5, producto2); chart = ChartFactory.createBarChart("Grafico de Barra", "Dia", "Cantidad", data, PlotOrientation.VERTICAL, true, true, true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainGridlinesVisible(true); } else { //Grafico de Torta DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Categoria1", 20); data.setValue("Categoria2", 400); data.setValue("Categoria3", 60); chart = ChartFactory.createPieChart3D("Grafico de Torta", data, true, true, true); } } panel = new ChartPanel(chart); panel.setBounds(5, 10, 410, 400); if (b.isSelected()) {//Barra GraficoBarra.add(panel); GraficoBarra.repaint(); } else { if (l.isSelected()) {//Linea GraficoLinea.add(panel); GraficoLinea.repaint(); } else { //Torta GraficoTorta.add(panel); GraficoTorta.repaint(); } } }
From source file:windows.sensorWindow.java
/** * creates all relevant data and adds it into the corresponding maps * //from w w w. ja v a 2 s .c o m * @param UID * UID of the plotting sensor */ @SuppressWarnings("deprecation") public static void addPlot(Brick newBrick) { // create series TimeSeries newSeries = new TimeSeries("" + 0, Millisecond.class); TimeSeries newSeries2 = new TimeSeries("" + 0, Millisecond.class); TimeSeries newSeries3 = new TimeSeries("" + 0, Millisecond.class); TimeSeries newSeries4 = new TimeSeries("" + 0, Millisecond.class); TimeSeries newSeries5 = new TimeSeries("" + 0, Millisecond.class); TimeSeries newSeries6 = new TimeSeries("" + 0, Millisecond.class); Measurement m1 = new Measurement(maxValues, maxCycles, newBrick.uid, 0); valuesMap.put(newBrick.uid, m1); if (newBrick.checked3 == true) { Measurement m2 = new Measurement(maxValues, maxCycles, newBrick.uid, 1); values2Map.put(newBrick.uid, m2); } // create entry in state map plot1StateMap.put(newBrick.uid, 0); plot2StateMap.put(newBrick.uid, 0); // create index map entry tmplindex.put(newBrick.uid, 0); // create avrgCtrlEnabled maps if (newBrick.controlAverage == true) avrgCtrl1Enabled.put(newBrick.uid, true); else avrgCtrl1Enabled.put(newBrick.uid, false); if (newBrick.controlAverage2 == true) avrgCtrl2Enabled.put(newBrick.uid, true); else avrgCtrl2Enabled.put(newBrick.uid, false); // create series map entry seriesMap.put(newBrick.uid, newSeries); seriesMap2.put(newBrick.uid, newSeries2); seriesMap3.put(newBrick.uid, newSeries3); seriesMap4.put(newBrick.uid, newSeries4); seriesMap5.put(newBrick.uid, newSeries3); seriesMap6.put(newBrick.uid, newSeries4); // create collection map entry seriesCollectionMap.put(newBrick.uid, new TimeSeriesCollection(newSeries)); seriesCollectionMap2.put(newBrick.uid, new TimeSeriesCollection(newSeries2)); tmplCollection1_1.put(newBrick.uid, new TimeSeriesCollection(newSeries3)); tmplCollection1_2.put(newBrick.uid, new TimeSeriesCollection(newSeries4)); tmplCollection2_1.put(newBrick.uid, new TimeSeriesCollection(newSeries5)); tmplCollection2_2.put(newBrick.uid, new TimeSeriesCollection(newSeries6)); // create plot map entry, special case for current/voltage brick, since // it has 2 parallel measurements and therefore 2 graphs must be treated XYPlot tmpSubPlot; tmpSubPlot = new XYPlot(seriesCollectionMap.get(newBrick.uid), null, null, new StandardXYItemRenderer()); // create the 1st graph if (newBrick.checked2 == true) { // create plot map entry NumberAxis rangeAxis = new NumberAxis( String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier))); rangeAxis.setAutoRangeIncludesZero(true); tmpSubPlot.setRangeAxis(0, rangeAxis); rangeAxis.setLabelPaint(Color.BLUE); rangeAxis.setVisible(newBrick.checked2); tmpSubPlot.setDataset(0, seriesCollectionMap.get(newBrick.uid)); // set dot - shape // Shape cross = ShapeUtilities.createDiagonalCross(3, 1); // create and store renderer XYItemRenderer renderer1 = new XYLineAndShapeRenderer(); renderer1 = tmpSubPlot.getRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); renderer1.setSeriesStroke(0, new BasicStroke(3)); // line = dashes: // float dash[] = {5.0f}; // renderer1.setSeriesStroke( 0, new // BasicStroke(3,BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, // 10.0f, dash, 0.0f)); // renderer1.setSeriesShape(0, cross); tmpSubPlot.setRenderer(0, renderer1); // set colors tmpSubPlot.setBackgroundPaint(Color.white); tmpSubPlot.setDomainGridlinePaint(Color.lightGray); tmpSubPlot.setRangeGridlinePaint(Color.lightGray); // tmpSubPlot.setRenderer(renderer2); // set font rangeAxis.setLabelFont(customFonts.get("axisLabelFont")); rangeAxis.setTickLabelFont(customFonts.get("axisValueFont")); // create template graph // if (newBrick.ctrlTmpl[0] == true) // { tmpSubPlot.setDataset(2, tmplCollection1_1.get(newBrick.uid)); XYItemRenderer renderer3 = new XYLineAndShapeRenderer(); int width = computeTmplPlotWidth(newBrick.tmpl1Width); BasicStroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);// , 10.0f, dash, 0.0f); renderer3.setSeriesPaint(0, Color.GREEN); // renderer3.setSeriesStroke( 0, new BasicStroke( 1 ) ); renderer3.setSeriesStroke(0, stroke); renderer3.setSeriesVisible(0, newBrick.ctrlTmpl[0]); rendererMap3.put(newBrick.uid, renderer3); tmpSubPlot.setRenderer(2, rendererMap3.get(newBrick.uid)); // } // put everything to the maps rendererMap.put(newBrick.uid, renderer1); plotMap.put(newBrick.uid, tmpSubPlot); axisMap.put(newBrick.uid, rangeAxis); } // create the 2nd graph if (newBrick.checked3 == true) { // set second axis for voltage/ampere brick NumberAxis secondaryAxis = new NumberAxis( String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier))); secondaryAxis.setAutoRangeIncludesZero(true); tmpSubPlot.setRangeAxis(1, secondaryAxis); secondaryAxis.setLabelPaint(Color.RED); secondaryAxis.setVisible(newBrick.checked3); tmpSubPlot.setDataset(1, seriesCollectionMap2.get(newBrick.uid)); tmpSubPlot.mapDatasetToRangeAxis(1, 1); // set font secondaryAxis.setLabelFont(customFonts.get("axisLabelFont")); secondaryAxis.setTickLabelFont(customFonts.get("axisValueFont")); // create and store renderer XYItemRenderer renderer2 = new StandardXYItemRenderer(); // renderer2 = tmpSubPlot.getRenderer(); renderer2.setSeriesPaint(1, Color.RED); renderer2.setSeriesStroke(0, new BasicStroke(3)); tmpSubPlot.setRenderer(1, renderer2); // set colors tmpSubPlot.setBackgroundPaint(Color.white); tmpSubPlot.setDomainGridlinePaint(Color.lightGray); tmpSubPlot.setRangeGridlinePaint(Color.lightGray); // ---------------------------------------------------------------------------------- // create min1 critical map value ValueMarker vm5 = new ValueMarker(newBrick.tresholdMin2); markerMapMin2Critical.put(newBrick.uid, vm5); // set critical line markerMapMin2Critical.get(newBrick.uid).setPaint(Color.red); markerMapMin2Critical.get(newBrick.uid).setLabel( String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)) + " critical min"); markerMapMin2Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_RIGHT); markerMapMin2Critical.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_RIGHT); tmpSubPlot.addRangeMarker(1, markerMapMin2Critical.get(newBrick.uid), Layer.BACKGROUND); // create min1 warning map value ValueMarker vm6 = new ValueMarker( newBrick.tresholdMin2 + newBrick.tresholdMin2 * warningPercentage / 100); markerMapMin2Warning.put(newBrick.uid, vm6); // set warning line markerMapMin2Warning.get(newBrick.uid).setPaint(Color.orange); markerMapMin2Warning.get(newBrick.uid).setLabel( String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)) + " warning min"); markerMapMin2Warning.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_RIGHT); markerMapMin2Warning.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_RIGHT); // tmpSubPlot.addRangeMarker(markerMapMin2Warning.get(newBrick.uid)); tmpSubPlot.addRangeMarker(1, markerMapMin2Warning.get(newBrick.uid), Layer.BACKGROUND); // create max1 critical map value ValueMarker vm7 = new ValueMarker(newBrick.tresholdMax2); markerMapMax2Critical.put(newBrick.uid, vm7); // set critical line markerMapMax2Critical.get(newBrick.uid).setPaint(Color.red); markerMapMax2Critical.get(newBrick.uid).setLabel( String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)) + " critical max"); markerMapMax2Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_RIGHT); markerMapMax2Critical.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_RIGHT); tmpSubPlot.addRangeMarker(1, markerMapMax2Critical.get(newBrick.uid), Layer.BACKGROUND); // create max1 warning map value ValueMarker vm8 = new ValueMarker( newBrick.tresholdMax2 + newBrick.tresholdMax2 * warningPercentage / 100); markerMapMax2Warning.put(newBrick.uid, vm8); // set warning line markerMapMax2Warning.get(newBrick.uid).setPaint(Color.orange); markerMapMax2Warning.get(newBrick.uid).setLabel( String.valueOf(constants.brick2ndUnitMap.get(newBrick.deviceIdentifier)) + " warning max"); markerMapMax2Warning.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_RIGHT); markerMapMax2Warning.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_RIGHT); tmpSubPlot.addRangeMarker(1, markerMapMax2Warning.get(newBrick.uid), Layer.BACKGROUND); // create and add min, max and average markers // create maxima marker ValueMarker vmMax = new ValueMarker(0); vmMax.setPaint(Color.orange); vmMax.setLabel("max"); vmMax.setLabelAnchor(RectangleAnchor.TOP_RIGHT); vmMax.setLabelTextAnchor(TextAnchor.TOP_RIGHT); // create minima marker ValueMarker vmMin = new ValueMarker(0); vmMin.setPaint(Color.orange); vmMin.setLabel("min"); vmMin.setLabelAnchor(RectangleAnchor.TOP_RIGHT); vmMin.setLabelTextAnchor(TextAnchor.TOP_RIGHT); // create average marker ValueMarker vmAvg = new ValueMarker(0); vmAvg.setPaint(Color.red); vmAvg.setLabel("average"); vmAvg.setLabelAnchor(RectangleAnchor.TOP_RIGHT); vmAvg.setLabelTextAnchor(TextAnchor.TOP_RIGHT); // add to maps marker2Maxima.put(newBrick.uid, vmMax); marker2Minima.put(newBrick.uid, vmMin); marker2Average.put(newBrick.uid, vmAvg); // add to plot tmpSubPlot.addRangeMarker(1, vmMax, Layer.BACKGROUND); tmpSubPlot.addRangeMarker(1, vmMin, Layer.BACKGROUND); tmpSubPlot.addRangeMarker(1, vmAvg, Layer.BACKGROUND); // create and add avrgCntrMarkers // create upper marker ValueMarker avrgCtrl2high = new ValueMarker(newBrick.getAvg2high()); avrgCtrl2high.setPaint(Color.orange); avrgCtrl2high.setLabel("avrg high"); avrgCtrl2high.setLabelAnchor(RectangleAnchor.TOP_RIGHT); avrgCtrl2high.setLabelTextAnchor(TextAnchor.TOP_RIGHT); // create lower marker ValueMarker avrgCtrl2low = new ValueMarker(newBrick.getAvg2low()); avrgCtrl2low.setPaint(Color.orange); avrgCtrl2low.setLabel("avrg low"); avrgCtrl2low.setLabelAnchor(RectangleAnchor.TOP_RIGHT); avrgCtrl2low.setLabelTextAnchor(TextAnchor.TOP_RIGHT); // add both markers avrg2High.put(newBrick.uid, avrgCtrl2high); avrg2Low.put(newBrick.uid, avrgCtrl2low); // add both to plot if (newBrick.controlAverage2) { tmpSubPlot.addRangeMarker(1, avrgCtrl2high, Layer.BACKGROUND); tmpSubPlot.addRangeMarker(1, avrgCtrl2low, Layer.BACKGROUND); } // ---------------------------------------------------------------------------------- // put everything to the map rendererMap2.put(newBrick.uid, renderer2); plotMap.put(newBrick.uid, tmpSubPlot); axisMap2.put(newBrick.uid, secondaryAxis); } // 1st graph // markers-------------------------------------------------------------------------------------------------- // create min1 critical map value ValueMarker vm1 = new ValueMarker(newBrick.tresholdMin1); markerMapMin1Critical.put(newBrick.uid, vm1); // set critical line markerMapMin1Critical.get(newBrick.uid).setPaint(Color.red); // / .setLabel("critical"); // markerMapMin1Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.BOTTOM); markerMapMin1Critical.get(newBrick.uid) .setLabel(String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)) + " critical min"); markerMapMin1Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_LEFT); markerMapMin1Critical.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_LEFT); plotMap.get(newBrick.uid).addRangeMarker(markerMapMin1Critical.get(newBrick.uid)); // create min1 warning map value ValueMarker vm2 = new ValueMarker(newBrick.tresholdMin1 + newBrick.tresholdMin1 * warningPercentage / 100); markerMapMin1Warning.put(newBrick.uid, vm2); // set warning line markerMapMin1Warning.get(newBrick.uid).setPaint(Color.orange); // marker2Map.get(newBrick.uid).setPaint(Color.); // / marker2Map.get(newBrick.uid).setLabel("warning"); markerMapMin1Warning.get(newBrick.uid) .setLabel(String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)) + " warning min"); markerMapMin1Warning.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_LEFT); markerMapMin1Warning.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_LEFT); plotMap.get(newBrick.uid).addRangeMarker(markerMapMin1Warning.get(newBrick.uid)); // create max1 critical map value ValueMarker vm3 = new ValueMarker(newBrick.tresholdMax1); markerMapMax1Critical.put(newBrick.uid, vm3); // set critical line markerMapMax1Critical.get(newBrick.uid).setPaint(Color.red); // / .setLabel("critical"); // markerMapMax1Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.BOTTOM); markerMapMax1Critical.get(newBrick.uid) .setLabel(String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)) + " critical max"); markerMapMax1Critical.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_LEFT); markerMapMax1Critical.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_LEFT); plotMap.get(newBrick.uid).addRangeMarker(markerMapMax1Critical.get(newBrick.uid)); // create max1 warning map value ValueMarker vm4 = new ValueMarker(newBrick.tresholdMax1 + newBrick.tresholdMax1 * warningPercentage / 100); markerMapMax1Warning.put(newBrick.uid, vm4); // set warning line markerMapMax1Warning.get(newBrick.uid).setPaint(Color.orange); markerMapMax1Warning.get(newBrick.uid) .setLabel(String.valueOf(constants.brickUnitMap.get(newBrick.deviceIdentifier)) + " warning max"); markerMapMax1Warning.get(newBrick.uid).setLabelAnchor(RectangleAnchor.TOP_LEFT); markerMapMax1Warning.get(newBrick.uid).setLabelTextAnchor(TextAnchor.TOP_LEFT); plotMap.get(newBrick.uid).addRangeMarker(markerMapMax1Warning.get(newBrick.uid)); // create and add min, max and average markers // create maxima marker ValueMarker vmMax = new ValueMarker(0); vmMax.setPaint(Color.cyan); vmMax.setLabel("max"); vmMax.setLabelAnchor(RectangleAnchor.TOP_LEFT); vmMax.setLabelTextAnchor(TextAnchor.TOP_LEFT); // create minima marker ValueMarker vmMin = new ValueMarker(0); vmMin.setPaint(Color.cyan); vmMin.setLabel("min"); vmMin.setLabelAnchor(RectangleAnchor.TOP_LEFT); vmMin.setLabelTextAnchor(TextAnchor.TOP_LEFT); // create average marker ValueMarker vmAvg = new ValueMarker(0); vmAvg.setPaint(Color.blue); vmAvg.setLabel("average"); vmAvg.setLabelAnchor(RectangleAnchor.TOP_LEFT); vmAvg.setLabelTextAnchor(TextAnchor.TOP_LEFT); // add to maps markerMaxima.put(newBrick.uid, vmMax); markerMinima.put(newBrick.uid, vmMin); markerAverage.put(newBrick.uid, vmAvg); // add to plot plotMap.get(newBrick.uid).addRangeMarker(vmMax); plotMap.get(newBrick.uid).addRangeMarker(vmMin); plotMap.get(newBrick.uid).addRangeMarker(vmAvg); // create and add avrgCntrMarkers // create upper marker ValueMarker avrgCtrl1high = new ValueMarker(newBrick.getAvg1high()); avrgCtrl1high.setPaint(Color.orange); avrgCtrl1high.setLabel("avrg high"); avrgCtrl1high.setLabelAnchor(RectangleAnchor.TOP_LEFT); avrgCtrl1high.setLabelTextAnchor(TextAnchor.TOP_LEFT); // create lower marker ValueMarker avrgCtrl1low = new ValueMarker(newBrick.getAvg1low()); avrgCtrl1low.setPaint(Color.orange); avrgCtrl1low.setLabel("avrg low"); avrgCtrl1low.setLabelAnchor(RectangleAnchor.TOP_LEFT); avrgCtrl1low.setLabelTextAnchor(TextAnchor.TOP_LEFT); // add both markers avrg1High.put(newBrick.uid, avrgCtrl1high); avrg1Low.put(newBrick.uid, avrgCtrl1low); // add both to plot if (newBrick.controlAverage) { plotMap.get(newBrick.uid).addRangeMarker(avrgCtrl1high); plotMap.get(newBrick.uid).addRangeMarker(avrgCtrl1low); } // ----------------------------------------------------------------------------------------------------- // set title NumberAxis axisForTitleOnly = new NumberAxis( data.constants.brickIdMap.get(newBrick.deviceIdentifier) + " (" + newBrick.uid + ")"); axisForTitleOnly.setLabelFont(customFonts.get("titleFont")); axisForTitleOnly.setTickLabelsVisible(false); axisForTitleOnly.setTickMarksVisible(false); axisForTitleOnly.setMinorTickMarksVisible(false); axisForTitleOnly.setAxisLineVisible(false); plotMap.get(newBrick.uid).setDomainAxis(1, axisForTitleOnly); // add subplot to the main plot plot.add(plotMap.get(newBrick.uid)); }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo2.java
private static JFreeChart createXYStepChart(XYDataset dataset) { DateAxis xAxis = new DateAxis(xAxisLabel); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); XYToolTipGenerator toolTipGenerator = null; if (tooltips) { toolTipGenerator = new StandardXYToolTipGenerator(); }/*ww w. j a v a2s . c o m*/ XYURLGenerator urlGenerator = null; if (urls) { urlGenerator = new StandardXYURLGenerator(); } XYItemRenderer renderer = new XYStepRenderer(toolTipGenerator, urlGenerator); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); plot.setRenderer(renderer); plot.setOrientation(orientation); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); JFreeChart chart = new JFreeChart("XYStep Chart Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, legend); chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MM-yyyy")); return chart; }
From source file:dk.netarkivet.harvester.harvesting.monitor.StartedJobHistoryChartGen.java
/** * Generates a chart in PNG format./*from ww w . ja v a2 s . c o m*/ * @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); } }