List of usage examples for org.jfree.chart.plot XYPlot setDataset
public void setDataset(int index, XYDataset dataset)
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Displays an XY chart that is periodically updated by a background thread. This is to * demonstrate the event notification system that automatically updates charts as required. * * @return a chart./* ww w . ja v a 2 s .c o m*/ */ public JFreeChart createCombinedAndOverlaidDynamicXYChart() { // chart title and axis labels... final String title = this.resources.getString("combined.dynamic.title"); final String subtitleStr = this.resources.getString("combined.dynamic.subtitle"); final String domainAxisLabel = this.resources.getString("combined.dynamic.domain"); final String[] ranges = this.resources.getStringArray("combined.dynamic.ranges"); // setup sample base 2-series dataset final SampleXYDataset data = new SampleXYDataset(); // create some SubSeriesDatasets and CombinedDatasets to test events final XYDataset series0 = new SubSeriesDataset(data, 0); final XYDataset series1 = new SubSeriesDataset(data, 1); final CombinedDataset combinedData = new CombinedDataset(); combinedData.add(series0); combinedData.add(series1); // create common time axis final NumberAxis timeAxis = new NumberAxis(domainAxisLabel); timeAxis.setTickMarksVisible(true); timeAxis.setAutoRangeIncludesZero(false); // make one vertical axis for each (vertical) chart final NumberAxis[] valueAxis = new NumberAxis[4]; for (int i = 0; i < valueAxis.length; i++) { valueAxis[i] = new NumberAxis(ranges[i]); valueAxis[i].setAutoRangeIncludesZero(false); } final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(timeAxis); // add subplot1... final XYItemRenderer renderer0 = new StandardXYItemRenderer(); final XYPlot subplot0 = new XYPlot(series0, null, valueAxis[0], renderer0); plot.add(subplot0, 1); // add subplot2... final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final XYPlot subplot1 = new XYPlot(series1, null, valueAxis[1], renderer1); plot.add(subplot1, 1); // add subplot3... final XYPlot subplot2 = new XYPlot(series0, null, valueAxis[2], new StandardXYItemRenderer()); subplot2.setDataset(1, series1); subplot2.setRenderer(1, new StandardXYItemRenderer()); plot.add(subplot2, 1); // add subplot4... final XYItemRenderer renderer3 = new StandardXYItemRenderer(); final XYPlot subplot3 = new XYPlot(data, null, valueAxis[3], renderer3); plot.add(subplot3, 1); final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.cyan)); // setup thread to update base Dataset final SampleXYDatasetThread update = new SampleXYDatasetThread(data); final Thread thread = new Thread(update); thread.start(); return chart; }
From source file:com.zigabyte.stock.stratplot.StrategyPlotter.java
/** Build combined chart containing the account cash/stocks/total values chart over dates on bottom and the percentage change over dates chart on top. // w w w.ja v a 2 s. c o m @return y-axes that need to be re-ranged when data changes. **/ private NumberAxis[] plotAccountHistory(XYDataset accountData, String title, Date startDate, Date endDate) { final DateAxis dateAxis = new DateAxis(); dateAxis.setRange(startDate, endDate); final NumberAxis percentAxis = new NumberAxis("% change"); percentAxis.setAutoRangeIncludesZero(false); final NumberAxis priceAxis = new NumberAxis("US$"); priceAxis.setAutoRangeIncludesZero(true); boolean useShapes = // use shapes if 3 months or less (endDate.getTime() - startDate.getTime() < 93 * 24 * 60 * 60 * 1000L); XYLineAndShapeRenderer accountRenderer = new XYLineAndShapeRenderer(); accountRenderer.setShapesVisible(useShapes); XYPlot accountPlot = new XYPlot(accountData, dateAxis, priceAxis, accountRenderer); // compare only total percent data to zoom in on its fluctuations // for comparison with the compare index such as S&P500 index. // Stock value starts at zero, and cash value becomes close to zero, // so they fluctuation widely, so leave them out. XYDataset accountTotalPercentData = new XYDatasetPercentChangeAdapter( new SubSeriesDataset(accountData, BalanceHistoryXYDataset.TOTAL_SERIES)); XYLineAndShapeRenderer compareRenderer = new XYLineAndShapeRenderer(); compareRenderer.setShapesVisible(useShapes); XYPlot comparePlot = new XYPlot(accountTotalPercentData, dateAxis, percentAxis, compareRenderer); String compareIndexSymbol = this.compareIndexSymbolField.getText(); StockHistory compareHistory = this.histories.get(compareIndexSymbol); if (compareHistory != null) { XYDataset comparePercentData = new OHLCDatasetPercentChangeAdapter(new OHLCDatasetSubdomainAdapter( new OHLCDatasetOfStockHistory(compareHistory), startDate, endDate)); int compareIndex = 1; comparePlot.setDataset(compareIndex, comparePercentData); XYLineAndShapeRenderer percentRenderer = new XYLineAndShapeRenderer(); percentRenderer.setShapesVisible(useShapes); comparePlot.setRenderer(compareIndex, percentRenderer); } // share date axis CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(dateAxis); combinedPlot.add(comparePlot, 1); combinedPlot.add(accountPlot, 1); this.chartPanel.setChart(new JFreeChart(title, null, combinedPlot, true)); return new NumberAxis[] { priceAxis, percentAxis }; }
From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.GOESChartUIComponent.java
/*********************************************************************************************** * Customise the XYPlot of a new chart, e.g. for fixed range axes. * * @param datasettype/*from w ww .java 2s. co m*/ * @param primarydataset * @param secondarydatasets * @param updatetype * @param displaylimit * @param channelselector * @param debug * * @return JFreeChart */ public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset, final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final JFreeChart jFreeChart; // A plain Chart is an XYPlot // with a DateAxis for the x-axis (index 0) and a NumberAxis for the y-axis (index 0). // The default renderer is an XYLineAndShapeRenderer jFreeChart = ChartHelper.createChart(primarydataset, ObservatoryInstrumentHelper.getCurrentObservatoryTimeZone(REGISTRY.getFramework(), getDAO(), debug), getMetadata(), getChannelCount(), hasTemperatureChannel(), updatetype, displaylimit, channelselector, debug); // Customise the Chart for GOES data // Channels 0 & 1 are Data on a LogarithmicAxis, // Channel 2 is Ratio on a NumberAxis if (jFreeChart != null) { final String strLabelFlux; final String strLabelRatio; final XYPlot plot; final LogarithmicAxis axisFlux; final DateAxis axisDate; // The set of Metadata available should include the Instrument // and any items from the current observation strLabelFlux = MetadataHelper.getMetadataValueByKey(getMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ZERO); strLabelRatio = MetadataHelper.getMetadataValueByKey(getMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ONE); plot = jFreeChart.getXYPlot(); //---------------------------------------------------------------------------------- // Replace the RangeAxis at index 0 NumberAxis with a LogarithmicAxis // The RangeAxis at index 0 is the LogarithmicAxis, to be used by Channels 0 & 1 (Data) axisFlux = new LogarithmicAxis(strLabelFlux); axisFlux.setRange(1.0E-09, 1.0E-02); axisFlux.setAllowNegativesFlag(false); axisFlux.setLog10TickLabelsFlag(true); plot.setRangeAxis(0, axisFlux); // Map the dataset to the axis plot.setDataset(INDEX_FLUX, primarydataset); plot.mapDatasetToRangeAxis(0, 0); plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); //---------------------------------------------------------------------------------- // Customise the DomainAxis at index 0 axisDate = (DateAxis) plot.getDomainAxis(); // Showing the YYYY-MM-DD makes a very long label... // ToDo Consider ThreadLocal axisDate.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); // Now customise the Flux renderer to improve legend visibility // Use the same colours as on http://www.swpc.noaa.gov/ // blue=0.5 - 4.0A red=1.0 - 8.0A ChartUIHelper.customisePlotRenderer(plot, INDEX_FLUX); //---------------------------------------------------------------------------------- // Set the RangeAxis at index 1 to a new NumberAxis, to be used by Channel 2 (Ratio) if ((secondarydatasets != null) && (secondarydatasets.size() == 1)) { final NumberAxis axisRatio; final XYLineAndShapeRenderer rendererRatio; axisRatio = new NumberAxis(strLabelRatio); plot.setRangeAxis(1, axisRatio); // The RangeAxis at index 1 is the NumberAxis, to be used by Channel 2 plot.setDataset(INDEX_RATIO, secondarydatasets.get(0)); plot.mapDatasetToRangeAxis(1, 1); plot.setRangeAxisLocation(1, AxisLocation.TOP_OR_RIGHT); rendererRatio = new XYLineAndShapeRenderer(); rendererRatio.setLinesVisible(true); rendererRatio.setShapesVisible(false); // Channel 2 is Ratio rendererRatio.setSeriesPaint(0, ChartUIHelper.getStandardColour(2).getColor()); rendererRatio.setLegendLine(SHAPE_LEGEND); plot.setRenderer(INDEX_RATIO, rendererRatio); //ChartHelper.customisePlotRenderer(plot, INDEX_RATIO); } } return (jFreeChart); }
From source file:org.moeaframework.analysis.plot.Plot.java
/** * Creates a new area plot series. The data will be stacked with * any preceding calls to {@code stacked}. The series is added to the given * dataset, or if {@code null} a new dataset is created. * //w w w. j ava2 s .c o m * @param label the label for the series * @param x the x values * @param y the y values * @param dataset the dataset, or {@code null} if a new dataset should be * created * @return a reference to this {@code Plot} instance */ private Plot stacked(String label, List<? extends Number> x, List<? extends Number> y, DefaultTableXYDataset dataset) { if (dataset == null) { createXYPlot(); XYPlot plot = chart.getXYPlot(); if (plot.getDataset(currentDataset) instanceof DefaultTableXYDataset) { dataset = (DefaultTableXYDataset) plot.getDataset(currentDataset); } else { currentDataset++; dataset = new DefaultTableXYDataset(); } } // generate the dataset XYSeries series = new XYSeries(label, true, false); for (int i = 0; i < x.size(); i++) { series.add(x.get(i), y.get(i)); } dataset.addSeries(series); // add the dataset to the plot XYPlot plot = chart.getXYPlot(); plot.setDataset(currentDataset, dataset); // setup the renderer Paint paint = paintHelper.get(dataset.getSeriesKey(0)); StackedXYAreaRenderer renderer = new StackedXYAreaRenderer(); renderer.setAutoPopulateSeriesStroke(false); renderer.setBaseStroke(new BasicStroke(3f, 1, 1)); renderer.setBasePaint(paint); renderer.setBaseFillPaint(paint); plot.setRenderer(currentDataset, renderer); return this; }
From source file:edu.unibonn.plotting.TimeSeriesPlotter_Sensors.java
private JFreeChart createChart(final XYDataset dataset, final XYDataset dataset_centroids, ArrayList<Cluster_KMeans> clusters) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Sensors", "Time", "Erlang", dataset, false, //t true, //t false //f );// w w w . j av a 2s . c om ChartUtilities.applyCurrentTheme(chart); //chart.setBackgroundPaint(Color.white); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); final XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; //rr.setPlotShapes(true); rr.setShapesFilled(true); rr.setItemLabelsVisible(true); } int temp_count = 0; //for (int i = 0; i < clusters.size(); i++) for (int i = 0; (i < 11) && (i < clusters.size()); i++) { Cluster_KMeans current_cluster = clusters.get(i); ArrayList<Sensor> member_time_series = current_cluster.getMembership(); for (int j = 0; j < member_time_series.size(); j++) { renderer.setSeriesPaint(j + temp_count, getColor(i)); } temp_count = temp_count + member_time_series.size(); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("HH:mm")); //final ValueAxis axis_y = plot.getRangeAxis(); //axis_y.setRange(0, 20); plot.setDataset(1, dataset_centroids); plot.setRenderer(1, new StandardXYItemRenderer()); for (int i = 0; (i < clusters.size()); i++) { //plot.getRenderer(1).setSeriesPaint(i, getColor(i)); plot.getRenderer(1).setSeriesPaint(i, Color.BLACK); plot.getRenderer(1).setSeriesStroke(i, new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); } plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:io.github.mzmine.modules.plots.msspectrum.MsSpectrumPlotWindowController.java
/** * Add a new spectrum to the plot./*from w ww. j av a 2 s . c o m*/ * * @param spectrum */ public void addSpectrum(@Nonnull MsSpectrum spectrum, @Nonnull String name) { Preconditions.checkNotNull(spectrum); if (!Platform.isFxApplicationThread()) { throw new IllegalStateException( "Not on FX application thread; currentThread = " + Thread.currentThread().getName()); } MsSpectrumDataSet newDataSet = new MsSpectrumDataSet(spectrum, name); newDataSet.mzShiftProperty().bind(mzShift); datasets.add(newDataSet); final int datasetIndex = numberOfDataSets; numberOfDataSets++; final XYPlot plot = chartNode.getChart().getXYPlot(); final Color newColor = plotColors[datasetIndex % plotColors.length]; newDataSet.setColor(newColor); configureRenderer(newDataSet, datasetIndex); newDataSet.renderingTypeProperty().addListener(e -> { Platform.runLater(() -> configureRenderer(newDataSet, datasetIndex)); }); newDataSet.colorProperty().addListener(e -> { Platform.runLater(() -> configureRenderer(newDataSet, datasetIndex)); }); newDataSet.lineThicknessProperty().addListener(e -> { Platform.runLater(() -> configureRenderer(newDataSet, datasetIndex)); }); newDataSet.showDataPointsProperty().addListener(e -> { Platform.runLater(() -> configureRenderer(newDataSet, datasetIndex)); }); // Once everything is configured, add the dataset to the plot plot.setDataset(datasetIndex, newDataSet); }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates and returns a sample overlaid chart. * <P>//w w w .j av a 2s.co m * Note: with the introduction of multiple secondary datasets in JFreeChart version 0.9.10, * the overlaid chart facility has been removed. You can achieve the same results using * a regular XYPlot with multiple datasets. * * @return an overlaid chart. */ public JFreeChart createOverlaidChart() { // create a default chart based on some sample data... final String title = this.resources.getString("combined.overlaid.title"); final String subtitleStr = this.resources.getString("combined.overlaid.subtitle"); final String domainAxisLabel = this.resources.getString("combined.overlaid.domain"); final String rangeAxisLabel = this.resources.getString("combined.overlaid.range"); // create high-low and moving average dataset final DefaultHighLowDataset highLowData = DemoDatasetFactory.createHighLowDataset(); // make an overlaid plot final ValueAxis domainAxis = new DateAxis(domainAxisLabel); final NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); rangeAxis.setAutoRangeIncludesZero(false); final XYItemRenderer renderer1 = new HighLowRenderer(); renderer1.setToolTipGenerator(new HighLowItemLabelGenerator()); final XYPlot plot = new XYPlot(highLowData, domainAxis, rangeAxis, renderer1); // overlay a moving average dataset final XYDataset maData = MovingAverage.createMovingAverage(highLowData, " (Moving Average)", 5 * 24 * 60 * 60 * 1000L, 5 * 24 * 60 * 60 * 1000L); plot.setDataset(1, maData); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); renderer2.setToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0"))); plot.setRenderer(1, renderer2); // make the top level JFreeChart object final JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); // then customise it a little... final TextTitle subtitle = new TextTitle(subtitleStr, new Font("SansSerif", Font.BOLD, 12)); chart.addSubtitle(subtitle); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); return chart; }
From source file:windows.sensorWindow.java
/** * creates all relevant data and adds it into the corresponding maps * /*from w ww. j a v a2 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.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.LogLinChartUIComponent.java
/*********************************************************************************************** * Customise the XYPlot of a new chart, e.g. for fixed range axes. * * @param datasettype/* ww w. jav a 2s .c o m*/ * @param primarydataset * @param secondarydatasets * @param updatetype * @param displaylimit * @param channelselector * @param debug * * @return JFreeChart */ public JFreeChart createCustomisedChart(final DatasetType datasettype, final XYDataset primarydataset, final List<XYDataset> secondarydatasets, final DataUpdateType updatetype, final int displaylimit, final ChannelSelectorUIComponentInterface channelselector, final boolean debug) { final String SOURCE = "LogLinChartUIComponent.createCustomisedChart "; final JFreeChart jFreeChart; LOGGER.debug(debug, SOURCE + "--> ChartHelper.createChart()"); MetadataHelper.showMetadataList(getMetadata(), SOURCE + " CHART METADATA --> ChartHelper.createChart()", LOADER_PROPERTIES.isMetadataDebug()); channelselector.debugSelector(debug, SOURCE); // Creates TimeSeriesChart or XYLineChart to suit the dataset // The default renderer is an XYLineAndShapeRenderer jFreeChart = ChartHelper.createChart(primarydataset, ObservatoryInstrumentHelper.getCurrentObservatoryTimeZone(REGISTRY.getFramework(), getDAO(), debug), getMetadata(), getChannelCount(), hasTemperatureChannel(), updatetype, displaylimit, channelselector, debug); if (jFreeChart != null) { // Customise the Chart for LogLin data if possible if ((hasLogarithmicMode()) && (!channelselector.isLinearMode())) { final XYPlot plot; final LogarithmicAxis axisLog; final String strAxisLabel; LOGGER.debug(debug, SOURCE + "Customise the Chart for LogLin data"); // The set of Metadata available should include the Instrument // and any items from the current observation strAxisLabel = MetadataHelper.getMetadataValueByKey(getMetadata(), MetadataDictionary.KEY_OBSERVATION_AXIS_LABEL_Y.getKey() + MetadataDictionary.SUFFIX_SERIES_ZERO); // Replace the RangeAxis at index 0 NumberAxis with a LogarithmicAxis axisLog = new LogarithmicAxis(strAxisLabel); axisLog.setAllowNegativesFlag(true); axisLog.setLog10TickLabelsFlag(true); if ((canAutorange()) && (channelselector.isAutoranging())) { axisLog.setAutoRange(true); axisLog.configure(); axisLog.autoAdjustRange(); } else { axisLog.setRange(getLogarithmicFixedMinY(), getLogarithmicFixedMaxY()); axisLog.configure(); axisLog.autoAdjustRange(); } plot = jFreeChart.getXYPlot(); plot.setRangeAxis(INDEX_AXIS, axisLog); plot.setRangeAxisLocation(INDEX_AXIS, AxisLocation.BOTTOM_OR_LEFT); // Map the dataset to the axis plot.setDataset(INDEX_DATA, primarydataset); plot.mapDatasetToRangeAxis(INDEX_DATA, INDEX_AXIS); // Change the DateAxis format if (DatasetType.TIMESTAMPED.equals(datasettype)) { final DateAxis axisDate; // Customise the DomainAxis at index 0 axisDate = (DateAxis) plot.getDomainAxis(); // Showing the YYYY-MM-DD makes a very long label... axisDate.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss")); } // Now customise the data renderer to improve legend visibility ChartUIHelper.customisePlotRenderer(plot, 0); } else { final XYPlot plot; LOGGER.debug(debug, SOURCE + "Customise the Chart for Linear data"); // Linear Mode // A default range suitable for display of dB ChartHelper.handleAutorangeForLinearMode(jFreeChart, channelselector, canAutorange(), getLinearFixedMinY(), getLinearFixedMaxY(), debug); // Now customise the data renderer to improve legend visibility plot = jFreeChart.getXYPlot(); ChartUIHelper.customisePlotRenderer(plot, 0); } } else { LOGGER.debug(debug, SOURCE + "Chart is NULL"); } return (jFreeChart); }
From source file:org.optaplanner.benchmark.impl.statistic.memoryuse.MemoryUseProblemStatistic.java
@Override public void writeGraphFiles(BenchmarkReport benchmarkReport) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Memory"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); int seriesIndex = 0; for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) { XYSeries usedSeries = new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " used"); // TODO enable max memory, but in the same color as used memory, but with a dotted line instead // XYSeries maxSeries = new XYSeries( // singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " max"); XYItemRenderer renderer = new XYLineAndShapeRenderer(); if (singleBenchmarkResult.isSuccess()) { MemoryUseSingleStatistic singleStatistic = (MemoryUseSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (MemoryUseStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); MemoryUseMeasurement memoryUseMeasurement = point.getMemoryUseMeasurement(); usedSeries.add(timeMillisSpent, memoryUseMeasurement.getUsedMemory()); // maxSeries.add(timeMillisSpent, memoryUseMeasurement.getMaxMemory()); }/*from w ww .java 2 s.co m*/ } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(usedSeries); // seriesCollection.addSeries(maxSeries); plot.setDataset(seriesIndex, seriesCollection); if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); // renderer.setSeriesStroke(1, new BasicStroke(2.0f)); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " memory use statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "MemoryUseStatistic"); }