List of usage examples for org.jfree.chart.plot XYPlot setDataset
public void setDataset(int index, XYDataset dataset)
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateCharts123(String outputdir) { try {//from ww w . j a va 2 s . c o m IniReader ir = new IniReader(outputdir + "/gdm_params.txt"); double intercept = ir.getDoubleValue("GDMODEL", "Intercept"); // 1. read the ObservedVsPredicted.csv file System.out.println("Loading csv data"); CSVReader csv = new CSVReader(new FileReader(outputdir + "ObservedVsPredicted.csv")); List<String[]> rawdata = csv.readAll(); double[][] dataCht1 = new double[2][rawdata.size() - 1]; double[][] dataCht2 = new double[2][rawdata.size() - 1]; // for Chart 1: obs count int[] obscount = new int[11]; for (int i = 0; i < obscount.length; i++) { obscount[i] = 0; } System.out.println("populating data"); for (int i = 1; i < rawdata.size(); i++) { String[] row = rawdata.get(i); double obs = Double.parseDouble(row[4]); dataCht1[0][i - 1] = Double.parseDouble(row[6]); dataCht1[1][i - 1] = obs; dataCht2[0][i - 1] = Double.parseDouble(row[5]) - intercept; dataCht2[1][i - 1] = obs; int obc = (int) Math.round(obs * 10); obscount[obc]++; } DefaultXYDataset dataset1 = new DefaultXYDataset(); dataset1.addSeries("", dataCht1); DefaultXYDataset dataset2 = new DefaultXYDataset(); dataset2.addSeries("", dataCht2); DefaultCategoryDataset dataset3 = new DefaultCategoryDataset(); for (int i = 0; i < obscount.length; i++) { String col = "0." + i + "-0." + (i + 1); if (i == 10) { col = "0.9-1.0"; } dataset3.addValue(obscount[i] + 100, "col", col); } generateChartByType("Response Histogram", "Observed Dissimilarity Class", "Number of Site Pairs", dataset3, outputdir, "bar", "resphist"); XYDotRenderer renderer = new XYDotRenderer(); //Shape cross = ShapeUtilities.createDiagonalCross(3, 1); //renderer.setSeriesShape(0, cross); renderer.setDotWidth(3); renderer.setDotHeight(3); renderer.setSeriesPaint(0, Color.BLACK); JFreeChart jChart1 = ChartFactory.createScatterPlot( "Observed versus predicted compositional dissimilarity", "Predicted Compositional Dissimilarity", "Observed Compositional Dissimilarity", dataset1, PlotOrientation.VERTICAL, false, false, false); jChart1.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); XYPlot plot = (XYPlot) jChart1.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRenderer(0, renderer); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setAutoRangeIncludesZero(false); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); double dMinPred = domain.getRange().getLowerBound(); double dMaxPred = domain.getRange().getUpperBound(); double dMinObs = range.getRange().getLowerBound(); double dMaxObs = range.getRange().getUpperBound(); System.out.println("1..pred.min.max: " + dMinPred + ", " + dMaxPred); int regressionLineSegs = 10; double dInc = (dMaxPred - dMinPred) / regressionLineSegs; double[][] dataReg1 = new double[2][regressionLineSegs + 1]; DefaultXYDataset dsReg1 = new DefaultXYDataset(); int i = 0; for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) { dataReg1[0][i] = d; dataReg1[1][i] = d; } dsReg1.addSeries("", dataReg1); XYSplineRenderer regressionRenderer = new XYSplineRenderer(); regressionRenderer.setBaseSeriesVisibleInLegend(true); regressionRenderer.setSeriesPaint(0, Color.RED); regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f)); regressionRenderer.setBaseShapesVisible(false); plot.setDataset(1, dsReg1); plot.setRenderer(1, regressionRenderer); System.out.println("Writing image...."); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/obspredissim.png"), jChart1, 600, 400); // For chart 3 JFreeChart jChart2 = ChartFactory.createScatterPlot( "Observed compositional dissimilarity vs predicted ecological distance", "Predicted ecological distance", "Observed Compositional Dissimilarity", dataset2, PlotOrientation.VERTICAL, false, false, false); jChart2.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); plot = (XYPlot) jChart2.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRenderer(0, renderer); domain = (NumberAxis) plot.getDomainAxis(); domain.setAutoRangeIncludesZero(false); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); dMinPred = domain.getRange().getLowerBound(); dMaxPred = domain.getRange().getUpperBound(); dMinObs = range.getRange().getLowerBound(); dMaxObs = range.getRange().getUpperBound(); System.out.println("2.pred.min.max: " + dMinPred + ", " + dMaxPred); regressionLineSegs = 10; dInc = (dMaxPred - dMinPred) / regressionLineSegs; dataReg1 = new double[2][regressionLineSegs + 1]; dsReg1 = new DefaultXYDataset(); i = 0; for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) { dataReg1[0][i] = d; dataReg1[1][i] = (1.0 - Math.exp(-d)); } dsReg1.addSeries("", dataReg1); regressionRenderer.setBaseSeriesVisibleInLegend(true); regressionRenderer.setSeriesPaint(0, Color.RED); regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f)); regressionRenderer.setBaseShapesVisible(false); plot.setDataset(1, dsReg1); plot.setRenderer(1, regressionRenderer); System.out.println("Writing image...."); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/dissimdist.png"), jChart2, 600, 400); } catch (Exception e) { System.out.println("Unable to generate charts 2 and 3:"); e.printStackTrace(System.out); } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.JFreeChartPlotEngine.java
private void pushDataAndRendererIntoPlot(XYPlot plot, int rangeAxisIdx, XYItemRenderer renderer, XYDataset dataset) throws ChartPlottimeException { if (dataset != null && renderer != null) { int datasetIdx = plot.getDatasetCount(); if (datasetIdx > 0 && plot.getDataset(datasetIdx - 1) == null) { datasetIdx -= 1;//from w w w .j a va 2 s .com } // push dataset and renderer into plot try { plot.setDataset(datasetIdx, dataset); // if Eclipse states that // dataset might not be // initialized, you did // not consider all // possibilities in the // condition block above } catch (RuntimeException e) { // probably this is because the domain axis contains values less // then zero and the scaling is logarithmic. // The shitty JFreeChart implementation does not throw a proper // exception stating what happened, // but just a RuntimeException with a string, so this is our // best guess: if (isProbablyZeroValuesOnLogScaleException(e)) { throw new ChartPlottimeException("gui.plotter.error.log_axis_contains_zero", "domain axis"); } else { throw e; } } plot.mapDatasetToRangeAxis(datasetIdx, rangeAxisIdx); plot.setRenderer(datasetIdx, renderer); } else { ChartPlottimeException chartPlottimeException = new ChartPlottimeException( new PlotConfigurationError("generic_plotter_error")); throw chartPlottimeException; } }
From source file:com.charts.OneMonthChart.java
public OneMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);//from www . ja v a2s .c o m rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setVerticalTickLabels(true); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM-dd")); xAxis.setAutoTickUnitSelection(false); xAxis.setAutoRange(false); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:com.charts.SixMonthChart.java
public SixMonthChart(YStockQuote currentStock) throws ParseException { DateAxis domainAxis = new DateAxis("Date"); NumberAxis rangeAxis = new NumberAxis("Price"); CandlestickRenderer renderer = new CandlestickRenderer(); XYDataset dataset = getDataSet(currentStock); XYPlot mainPlot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); //Do some setting up, see the API Doc renderer.setSeriesPaint(0, Color.BLACK); renderer.setDrawVolume(false);/*from w w w. j av a 2s.c o m*/ rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yy")); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); //Now create the chart and chart panel JFreeChart chart = new JFreeChart(currentStock.get_name(), null, mainPlot, false); chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(600, 300)); XYPlot plot = (XYPlot) chart.getPlot(); LegendTitle legend = new LegendTitle(plot); chart.addLegend(legend); chart.getLegend().setVisible(true); chart.getLegend().setPosition(RectangleEdge.BOTTOM); ValueAxis yAxis = (ValueAxis) plot.getRangeAxis(); DateAxis xAxis = (DateAxis) plot.getDomainAxis(); Date now = new Date(); SegmentedTimeline segmentedTimeline = SegmentedTimeline.newMondayThroughFridayTimeline(); Calendar[][] holidays = DayRange.getHolidayDates(); int len = holidays.length; for (int i = 0; i < holidays[0].length; i++) { Calendar day = Calendar.getInstance(TimeZone.getTimeZone("EST")); day.set(Calendar.YEAR, holidays[0][i].get(Calendar.YEAR)); day.set(Calendar.MONTH, holidays[0][i].get(Calendar.MONTH)); day.set(Calendar.DAY_OF_MONTH, holidays[0][i].get(Calendar.DAY_OF_MONTH)); day.set(Calendar.HOUR_OF_DAY, 9); segmentedTimeline.addException(day.getTime()); } xAxis.setTimeline(segmentedTimeline); //xAxis.setVerticalTickLabels(true); xAxis.setDateFormatOverride(new SimpleDateFormat("MMM y")); xAxis.setAutoTickUnitSelection(true); xAxis.setAutoRange(true); renderer.setAutoWidthFactor(0.5); renderer.setUpPaint(Color.green); renderer.setDownPaint(new Color(0xc0, 0x00, 0x00)); renderer.setSeriesPaint(0, Color.black); StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(); renderer1.setSeriesPaint(0, Color.BLUE); TimeSeries movingAverage30 = MovingAverage.createMovingAverage(close, "MA(30)", 30, 0); Double currMA30 = (Double) movingAverage30.getDataItem(movingAverage30.getItemCount() - 1).getValue(); currMA30 = Math.round(currMA30 * 100.0) / 100.0; movingAverage30.setKey("MA(30): " + currMA30); TimeSeriesCollection collection = new TimeSeriesCollection(); collection.addSeries(movingAverage30); plot.setDataset(1, collection); plot.setRenderer(1, renderer1); chartPanel.revalidate(); chartPanel.repaint(); chartPanel.revalidate(); chartPanel.repaint(); }
From source file:ec.ui.view.DistributionView.java
protected void onDataChange() { XYPlot plot = chartPanel.getChart().getXYPlot(); if (data != DEFAULT_DATA) { DescriptiveStatistics stats = new DescriptiveStatistics(new DataBlock(data)); double m = 0, M = 0, dv = 1; if (adjustDistribution && distribution != DEFAULT_DISTRIBUTION) { m = stats.getAverage();//from w w w.jav a2 s. c o m M = distribution.getExpectation(); double v = stats.getVar(); double V = distribution.getVariance(); dv = Math.sqrt(v / V); } final double xmin = stats.getMin() < lBound ? stats.getMin() : lBound; final double xmax = stats.getMax() > rBound ? stats.getMax() : rBound; final int n = hCount != 0 ? hCount : (int) Math.ceil(Math.sqrt(stats.getObservationsCount())); final double xstep = (xmax - xmin) / n; // distribution > if (distribution != DEFAULT_DISTRIBUTION) { Function2D density = new Function2D() { @Override public double getValue(double x) { return distribution.getDensity(x); } }; final double zmin = distribution.hasLeftBound() != BoundaryType.None ? distribution.getLeftBound() : ((xmin - xstep - m) / dv + M); final double zmax = distribution.hasRightBound() != BoundaryType.None ? distribution.getRightBound() : ((xmax + xstep - m) / dv + M); // TODO: create IDistribution#getName() method String name = distribution.getClass().getSimpleName(); ((XYLineAndShapeRenderer) plot.getRenderer(DISTRIBUTION_INDEX)) .setLegendItemToolTipGenerator(getTooltipGenerator(distribution)); plot.setDataset(DISTRIBUTION_INDEX, DatasetUtilities.sampleFunction2D(density, zmin, zmax, n, name)); } else { plot.setDataset(DISTRIBUTION_INDEX, Charts.emptyXYDataset()); } // < distribution // histogram > XYSeries hSeries = new XYSeries(""); double nobs = stats.getObservationsCount(); for (int i = 0; i <= n; ++i) { double x0 = xmin + i * xstep; double x1 = x0 + xstep; double y = stats.countBetween(x0, x1) / (nobs * xstep / dv); hSeries.add(((x0 + x1) / 2 - m) / dv + M, y); } plot.setDataset(HISTOGRAM_INDEX, new XYBarDataset(new XYSeriesCollection(hSeries), xstep / dv + M)); // < histogram } else { plot.setDataset(HISTOGRAM_INDEX, Charts.emptyXYDataset()); plot.setDataset(DISTRIBUTION_INDEX, Charts.emptyXYDataset()); } onColorSchemeChange(); }
From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java
private void plotDataSet(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape) throws ConvertException { double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY); String legend = shortLegend.get(id); Color color = colors.get(id); Shape shape = shapes.get(id); if (addInfoInLegend) { legend = longLegend.get(id);/*from ww w. j av a 2 s . c o m*/ } if (color == null) { color = defaultColor; } if (shape == null) { shape = defaultShape; } if (points != null) { DefaultXYDataset dataset = new DefaultXYDataset(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(drawLines, true); dataset.addSeries(legend, points); renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setSeriesPaint(0, color); renderer.setSeriesShape(0, shape); int i; if (plot.getDataset(0) == null) { i = 0; } else { i = plot.getDatasetCount(); } plot.setDataset(i, dataset); plot.setRenderer(i, renderer); } }
From source file:com.prezerak.windmill.gui.AveragesPanel.java
private void plotEverything() { try {//from www .j a v a 2s . com final XYPlot plot = chart.getXYPlot(); ValueAxis domainAxis = plot.getDomainAxis(); plot.getDomainAxis().setLowerMargin(0); plot.getDomainAxis().setUpperMargin(0); plot.getDomainAxis().setAutoRange(true); if (domainAxis instanceof DateAxis) { DateAxis axis = (DateAxis) domainAxis; // customise axis here... //axis.setRange(new Date(startDate), new Date(endDate)); long startT = datasetVel.getDataItem(0).getPeriod().getLastMillisecond(); long endT = datasetVel.getDataItem(datasetVel.getItemCount() - 1).getPeriod().getLastMillisecond(); ; DateFormat formatter; long duration = endT - startT; long _24hrs = 1000 * 60 * 60 * 24; long _3mins = 1000 * 60 * 3; if (duration > _24hrs) { formatter = new SimpleDateFormat("HH:mm dd-MMM"); } else if (endDate - startDate > _3mins && endDate - startDate <= _24hrs) formatter = new SimpleDateFormat("HH:mm"); else //smaller than 3mins formatter = new SimpleDateFormat("HH:mm:ss"); axis.setDateFormatOverride(formatter); } TimeSeriesCollection seriesVel = new TimeSeriesCollection(); seriesVel.addSeries(datasetVel); plot.setDataset(0, seriesVel); final NumberAxis velRangeAxis = (NumberAxis) plot.getRangeAxis(); velRangeAxis.setRange(0.0, maxY); plot.setRangeAxis(velRangeAxis); plot.mapDatasetToRangeAxis(0, 0); XYLineAndShapeRenderer velocityRenderer = (XYLineAndShapeRenderer) plot.getRenderer(0); velocityRenderer.setBaseShapesVisible(true); velocityRenderer.setBaseShapesFilled(false); velocityRenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("dd-MM-yy, hh:mm:ss a"), new DecimalFormat("00.0"))); velocityRenderer.setSeriesPaint(0, Color.BLACK); if (!rdbtnVelocity.isSelected()) { velocityRenderer.setSeriesVisible(0, false); } else { velocityRenderer.setSeriesVisible(0, true); } TimeSeriesCollection seriesDir = new TimeSeriesCollection(); seriesDir.addSeries(datasetDir); plot.setDataset(1, seriesDir); final ValueAxis dirRangeAxis = new NumberAxis("Direction"); dirRangeAxis.setRange(0.0, 370.0); plot.setRangeAxis(1, dirRangeAxis); plot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer dirRenderer = (XYLineAndShapeRenderer) plot.getRenderer(1); if (dirRenderer == null) dirRenderer = new XYLineAndShapeRenderer(); dirRenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("dd-MM-yy, hh:mm:ss a"), new DecimalFormat("00.0"))); plot.setRenderer(1, dirRenderer); dirRenderer.setSeriesPaint(0, Color.BLUE); if (!rdbtnDirection.isSelected()) { dirRenderer.setSeriesVisible(0, false); } else { dirRenderer.setSeriesVisible(0, true); } final ValueAxis alarmsRangeAxis = new NumberAxis("Alarms"); alarmsRangeAxis.setRange(0.0, 1); alarmsRangeAxis.setVisible(false); XYBarRenderer gustRenderer = null; TimePeriodValuesCollection seriesGust = new TimePeriodValuesCollection(datasetGust); plot.setDataset(2, seriesGust); plot.setRangeAxis(2, alarmsRangeAxis); plot.mapDatasetToRangeAxis(2, 2); gustRenderer = (XYBarRenderer) plot.getRenderer(2); if (gustRenderer == null) gustRenderer = new XYBarRenderer(); plot.setRenderer(2, gustRenderer); gustRenderer.setSeriesPaint(0, Color.PINK); if ((rdbtnVelocity.isSelected() || rdbtnDirection.isSelected()) && rdbtnGust.isSelected()) gustRenderer.setSeriesVisible(0, true); else gustRenderer.setSeriesVisible(0, false); XYBarRenderer higherRenderer = null; TimePeriodValuesCollection seriesHigher = new TimePeriodValuesCollection(datasetHigher); plot.setDataset(3, seriesHigher); plot.setRangeAxis(3, alarmsRangeAxis); plot.mapDatasetToRangeAxis(3, 2); higherRenderer = (XYBarRenderer) plot.getRenderer(3); if (higherRenderer == null) higherRenderer = new XYBarRenderer(); plot.setRenderer(3, higherRenderer); higherRenderer.setSeriesPaint(0, Color.RED); if ((rdbtnVelocity.isSelected() || rdbtnDirection.isSelected()) && rdbtnHigher.isSelected()) higherRenderer.setSeriesVisible(0, true); else higherRenderer.setSeriesVisible(0, false); TimePeriodValuesCollection seriesHigh = new TimePeriodValuesCollection(datasetHigh); plot.setDataset(4, seriesHigh); plot.setRangeAxis(4, alarmsRangeAxis); plot.mapDatasetToRangeAxis(4, 2); XYBarRenderer highRenderer = (XYBarRenderer) plot.getRenderer(4); if (highRenderer == null) highRenderer = new XYBarRenderer(); plot.setRenderer(4, highRenderer); highRenderer.setSeriesPaint(0, new Color(206, 33, 85)); if ((rdbtnVelocity.isSelected() || rdbtnDirection.isSelected()) && rdbtnHigh.isSelected()) highRenderer.setSeriesVisible(0, true); else highRenderer.setSeriesVisible(0, false); } catch (OutOfMemoryError e) { WindMill.logger.warn("Out of Memory in plotEverything"); } }
From source file:whitebox.stats.Kriging.java
/** * It gets the semivariogram type and bins list and draw a graph for them * TheoryVariogram should be called first * * @param bins/*from ww w.java 2 s. co m*/ * @param variogram */ public void DrawSemivariogram(bin[][] bins, Variogram variogram) { XYSeriesCollection sampleCollct = new XYSeriesCollection(); XYSeries series = new XYSeries("Sample Variogram"); // for (Iterator<bin> i = bins.iterator(); i.hasNext(); ) // { // series.add(bins.get(j).Distance,bins.get(j).Value); // i.next(); // j++; // } XYLineAndShapeRenderer xylineshapRend = new XYLineAndShapeRenderer(false, true); CombinedRangeXYPlot combinedrangexyplot = new CombinedRangeXYPlot(); for (int i = 0; i < bins[0].length; i++) { for (int k = 0; k < bins.length; k++) { if (!Double.isNaN(bins[k][i].Value)) { series.add(bins[k][i].Distance, bins[k][i].Value); } } sampleCollct.addSeries(series); double[][] res = CalcTheoreticalSVValues(variogram, series.getMaxX()); XYSeries seriesTSV = new XYSeries("Theoretical Variogram"); for (int l = 0; l < res.length; l++) { seriesTSV.add(res[l][0], res[l][1]); } XYSeriesCollection theorCollct = new XYSeriesCollection(); theorCollct.addSeries(seriesTSV); XYDataset xydataset = sampleCollct; XYPlot xyplot1 = new XYPlot(xydataset, new NumberAxis(), null, xylineshapRend); xyplot1.setDataset(1, theorCollct); XYLineAndShapeRenderer lineshapRend = new XYLineAndShapeRenderer(true, false); xyplot1.setRenderer(1, lineshapRend); xyplot1.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); combinedrangexyplot.add(xyplot1); } DecimalFormat df = new DecimalFormat("###,##0.000"); String title = "Semivariogram (RMSE = " + df.format(Math.sqrt(variogram.mse)) + ")"; JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, combinedrangexyplot, true); // JFreeChart chart = ChartFactory.createScatterPlot( // "Semivariogram", // chart title // "Distance", // x axis label // "Moment of Inertia", // y axis label // result, // data // PlotOrientation.VERTICAL, // true, // include legend // true, // tooltips // false // urls // ); // create and display a frame... ChartFrame frame = new ChartFrame("Semivariogram", chart); frame.pack(); frame.setVisible(true); }
From source file:de.dmarcini.submatix.pclogger.gui.spx42LogGraphPanel.java
/** * Erzeuge eine Grafik fr die Nullzeitanzeige Project: SubmatixBTForPC Package: de.dmarcini.submatix.pclogger.gui * /* w w w. ja v a 2 s.c o m*/ * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 02.08.2012 * @param diveList * @param thePlot */ private void makeNulltimeGraph(Vector<Integer[]> diveList, XYPlot thePlot) { XYDataset nullTimeDataSet; // lg.debug("create nulltime dataset"); nullTimeDataSet = createXYDataset(LangStrings.getString("spx42LogGraphPanel.graph.nulltimeScalaTitle"), diveList, ProjectConst.UNITS_DEFAULT, 0, LogDerbyDatabaseUtil.NULLTIME); final XYLineAndShapeRenderer lineNullTimeRenderer = new XYLineAndShapeRenderer(true, true); final LogarithmicAxis nullTimeAxis = new LogarithmicAxis( LangStrings.getString("spx42LogGraphPanel.graph.nulltimeAxisTitle")); nullTimeAxis.setNumberFormatOverride(new DecimalFormat("#.###")); lineNullTimeRenderer.setSeriesPaint(0, new Color(ProjectConst.GRAPH_NULLTIME_ACOLOR)); lineNullTimeRenderer.setSeriesShapesVisible(0, false); lineNullTimeRenderer.setDrawSeriesLineAsPath(true); nullTimeAxis.setAutoRange(false); nullTimeAxis.setRange(0.0D, 200.0D); // Lege die Nullzeit Axenreichweite auf ein bersichtliches Ma fest // nullTimeAxis.setAutoRangeIncludesZero( true ); thePlot.setRangeAxis(GRAPH_NULLTIME, nullTimeAxis); thePlot.mapDatasetToRangeAxis(GRAPH_NULLTIME, GRAPH_NULLTIME); thePlot.setDataset(GRAPH_NULLTIME, nullTimeDataSet); thePlot.setRenderer(GRAPH_NULLTIME, lineNullTimeRenderer); }