List of usage examples for org.jfree.chart.renderer.xy XYItemRenderer setSeriesStroke
public void setSeriesStroke(int series, Stroke stroke);
From source file:dbseer.gui.chart.DBSeerChartFactory.java
public static JFreeChart createXYLinePredictionChart(PredictionCenter center) throws Exception { StatisticalPackageRunner runner = DBSeerGUI.runner; String title = runner.getVariableString("title"); Object[] legends = (Object[]) runner.getVariableCell("legends"); Object[] xCellArray = (Object[]) runner.getVariableCell("Xdata"); Object[] yCellArray = (Object[]) runner.getVariableCell("Ydata"); String xLabel = runner.getVariableString("Xlabel"); String yLabel = runner.getVariableString("Ylabel"); XYSeriesCollection dataSet = new XYSeriesCollection(); int numLegends = legends.length; int numXCellArray = xCellArray.length; int numYCellArray = yCellArray.length; int dataCount = 0; if (numXCellArray != numYCellArray) { JOptionPane.showMessageDialog(null, "The number of X dataset and Y dataset does not match.", "The number of X dataset and Y dataset does not match.", JOptionPane.ERROR_MESSAGE); System.out.println(numXCellArray + " : " + numYCellArray); return null; }// w w w . ja va2 s.c om final java.util.List<String> transactionNames = center.getTrainConfig().getDataset(0) .getTransactionTypeNames(); for (int i = 0; i < numLegends; ++i) { String legend = (String) legends[i]; for (int j = 0; j < transactionNames.size(); ++j) { if (legend.contains("Type " + (j + 1))) { legends[i] = legend.replace("Type " + (j + 1), transactionNames.get(j)); break; } } } for (int j = 0; j < transactionNames.size(); ++j) { if (xLabel.contains("Type " + (j + 1))) { xLabel = xLabel.replace("Type " + (j + 1), transactionNames.get(j)); break; } } for (int j = 0; j < transactionNames.size(); ++j) { if (yLabel.contains("Type " + (j + 1))) { yLabel = yLabel.replace("Type " + (j + 1), transactionNames.get(j)); break; } } for (int i = 0; i < numYCellArray; ++i) { double[] xArray = (double[]) xCellArray[i]; runner.eval("yArraySize = size(Ydata{" + (i + 1) + "});"); runner.eval("yArray = Ydata{" + (i + 1) + "};"); double[] yArraySize = runner.getVariableDouble("yArraySize"); double[] yArray = runner.getVariableDouble("yArray"); int xLength = xArray.length; int row = (int) yArraySize[0]; int col = (int) yArraySize[1]; for (int c = 0; c < col; ++c) { XYSeries series; int legendIdx = (dataCount >= numLegends) ? numLegends - 1 : dataCount; String legend = (String) legends[legendIdx]; if (numLegends == 0) { series = new XYSeries("Data " + dataCount + 1); } else if (dataCount >= numLegends) { series = new XYSeries(legend + (dataCount + 1)); } else { series = new XYSeries(legend); } for (int r = 0; r < row; ++r) { int xRow = (r >= xLength) ? xLength - 1 : r; double yValue = yArray[r + c * row]; // remove negatives & NaN & infs. if (yValue < 0 || yValue == Double.NaN || yValue == Double.POSITIVE_INFINITY || yValue == Double.NEGATIVE_INFINITY) { yValue = 0.0; } series.add(xArray[xRow], yValue); } dataSet.addSeries(series); ++dataCount; } } JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataSet); // change 'predicted' data to have dotted lines. BasicStroke dashStroke = toStroke(STYLE_DASH); BasicStroke dotStroke = toStroke(STYLE_DOT); BasicStroke lineStroke = toStroke(STYLE_LINE); for (int i = 0; i < dataSet.getSeriesCount(); ++i) { String legend = (String) dataSet.getSeriesKey(i); XYPlot plot = chart.getXYPlot(); XYItemRenderer renderer = plot.getRenderer(); if (legend.contains("predicted") || legend.contains("Predicted")) { renderer.setSeriesStroke(i, dotStroke); } else { renderer.setSeriesStroke(i, lineStroke); } } return chart; }
From source file:com.griddynamics.jagger.reporting.chart.ChartHelper.java
public static JFreeChart createStackedAreaChart(String title, XYSeriesCollection areaData, XYSeriesCollection lineData, String xLabel, String yLabel, ColorTheme theme) { final ValueAxis xAxis = new NumberAxis(xLabel); final ValueAxis yAxis = new NumberAxis(yLabel); XYPlot mainPlot = new XYPlot(); mainPlot.setDomainAxis(xAxis);/*from ww w . j a va 2 s . co m*/ mainPlot.setRangeAxis(yAxis); mainPlot.setForegroundAlpha(0.9f); //[ stacked area DefaultTableXYDataset areaDs = new DefaultTableXYDataset(); for (int i = 0; i < areaData.getSeriesCount(); i++) { areaDs.addSeries(areaData.getSeries(i)); } XYItemRenderer stackedRenderer = new StackedXYAreaRenderer2(); mainPlot.setDataset(areaDs); mainPlot.setRenderer(stackedRenderer); Color[] colors = generateJetSpectrum(areaData.getSeriesCount()); for (int i = 0; i < areaData.getSeriesCount(); i++) { stackedRenderer.setSeriesPaint(i, colors[i]); } //] //[ lines if (lineData != null) { XYItemRenderer lineRenderer = new StandardXYItemRenderer(); DefaultTableXYDataset lineDs = new DefaultTableXYDataset(); for (int i = 0; i < lineData.getSeriesCount(); i++) { lineDs.addSeries(lineData.getSeries(i)); } mainPlot.setDataset(1, lineDs); mainPlot.setRenderer(1, lineRenderer); colors = new Color[] { Color.black, Color.red, Color.darkGray }; for (int i = 0; i < lineData.getSeriesCount(); i++) { lineRenderer.setSeriesPaint(i, colors[i % colors.length]); lineRenderer.setSeriesStroke(i, new BasicStroke(2f)); } } //] mainPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, mainPlot, true); formatColorTheme(chart, theme); return chart; }
From source file:org.jfree.chart.demo.MouseListenerDemo3.java
public void chartMouseClicked(ChartMouseEvent chartmouseevent) { org.jfree.chart.entity.ChartEntity chartentity = chartmouseevent.getEntity(); if (chartentity != null && (chartentity instanceof LegendItemEntity)) { LegendItemEntity legenditementity = (LegendItemEntity) chartentity; @SuppressWarnings("rawtypes") Comparable comparable = legenditementity.getSeriesKey(); XYPlot xyplot = (XYPlot) chart.getPlot(); XYDataset xydataset = xyplot.getDataset(); XYItemRenderer xyitemrenderer = xyplot.getRenderer(); for (int i = 0; i < xydataset.getSeriesCount(); i++) { xyitemrenderer.setSeriesStroke(i, new BasicStroke(1.0F)); if (xydataset.getSeriesKey(i).equals(comparable)) xyitemrenderer.setSeriesStroke(i, new BasicStroke(2.0F)); }/*from www . ja va 2s .c o m*/ } }
From source file:playground.dgrether.analysis.charts.DgAvgDeltaUtilsModeGroupChart.java
@Override public JFreeChart createChart() { XYPlot plot = new XYPlot(); ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]"); ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]"); plot.setDomainAxis(xAxis);//from ww w. ja v a 2s .c o m plot.setRangeAxis(yAxis); DgColorScheme colorScheme = new DgColorScheme(); XYItemRenderer renderer2; renderer2 = new XYLineAndShapeRenderer(true, true); plot.setDataset(0, this.dataset); for (int i = 0; i <= 3; i++) { renderer2.setSeriesStroke(i, new BasicStroke(2.0f)); renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f)); renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a")); } plot.setRenderer(0, renderer2); JFreeChart chart = new JFreeChart("", plot); chart.setBackgroundPaint(ChartColor.WHITE); chart.getLegend().setItemFont(this.axisBuilder.getAxisFont()); chart.setTextAntiAlias(true); return chart; }
From source file:greenapi.ui.charts.LineChartPanelSupport.java
public void setSeriesPaint(int serie, Color paramColor) { XYItemRenderer localXYItemRenderer = getPlot().getRenderer(); localXYItemRenderer.setSeriesPaint(serie, paramColor); localXYItemRenderer.setSeriesStroke(serie, this.getDefaultLineStroke()); getPlot().setRenderer(localXYItemRenderer); }
From source file:playground.dgrether.analysis.charts.DgMixedModeSwitcherOnlyDeltaScoreIncomeModeChoiceChart.java
public JFreeChart createChart() { XYPlot plot = new XYPlot(); ValueAxis xAxis = this.axisBuilder.createValueAxis("Income [Chf / Year]"); ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]"); plot.setDomainAxis(xAxis);/* w ww. j av a2 s . com*/ plot.setRangeAxis(yAxis); DgColorScheme colorScheme = new DgColorScheme(); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true); renderer1.setSeriesPaint(0, colorScheme.COLOR3B); renderer1.setSeriesPaint(1, colorScheme.COLOR4B); plot.setDataset(0, this.inomeModeChoiceDs); plot.setRenderer(0, renderer1); XYItemRenderer renderer2; renderer2 = new XYLineAndShapeRenderer(true, true); plot.setDataset(1, this.avgDeltaScoreIncomeDs); for (int i = 2; i <= 3; i++) { renderer2.setSeriesStroke(i - 2, new BasicStroke(2.0f)); renderer2.setSeriesOutlineStroke(i - 2, new BasicStroke(3.0f)); renderer2.setSeriesPaint(i - 2, colorScheme.getColor(i + 1, "a")); } plot.setRenderer(1, renderer2); JFreeChart chart = new JFreeChart("", plot); chart.setBackgroundPaint(ChartColor.WHITE); chart.getLegend().setItemFont(this.axisBuilder.getAxisFont()); chart.setTextAntiAlias(true); return chart; }
From source file:playground.dgrether.analysis.charts.DgMixedDeltaUtilsModeGroupChart.java
public JFreeChart createChart() { XYPlot plot = new XYPlot(); ValueAxis xAxis = this.axisBuilder.createValueAxis("% of Population Sorted by Income"); ValueAxis yAxis = this.axisBuilder.createValueAxis("Delta Utils [Utils]"); plot.setDomainAxis(xAxis);//from w w w . ja v a 2 s. co m plot.setRangeAxis(yAxis); //RANGE xAxis.setRange(0.0, 102.0); yAxis.setRange(-0.31, 0.61); DgColorScheme colorScheme = new DgColorScheme(); XYItemRenderer renderer1 = new XYLineAndShapeRenderer(false, true); renderer1.setSeriesPaint(0, colorScheme.COLOR1B); renderer1.setSeriesPaint(1, colorScheme.COLOR2B); renderer1.setSeriesPaint(2, colorScheme.COLOR3B); renderer1.setSeriesPaint(3, colorScheme.COLOR4B); plot.setDataset(0, this.inomeModeChoiceDs); plot.setRenderer(0, renderer1); XYItemRenderer renderer2; renderer2 = new XYLineAndShapeRenderer(true, true); plot.setDataset(1, this.avgDeltaScoreIncomeDs); for (int i = 0; i <= 3; i++) { renderer2.setSeriesStroke(i, new BasicStroke(2.0f)); renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f)); renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a")); } plot.setRenderer(1, renderer2); JFreeChart chart = new JFreeChart("", plot); chart.setBackgroundPaint(ChartColor.WHITE); chart.getLegend().setItemFont(this.axisBuilder.getAxisFont()); chart.setTextAntiAlias(true); return chart; }
From source file:carfuzzy.Operations.java
public JFreeChart setToChart(double input, double membership, XYSeries series, XYSeriesCollection collection, String x_axis) { // kurallari cizdirdikten sonra cizdir. series.add(input, membership);/*w ww . j a v a 2s .c o m*/ series.add(input, 0); series.add(0, membership); collection.addSeries(series); JFreeChart chart = XYGraph.drawChart(collection, x_axis, "Membership"); XYPlot plot = chart.getXYPlot(); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesStroke(collection.getSeriesCount() - 1, new BasicStroke(3.5f)); renderer.setSeriesStroke(collection.getSeriesCount() - 1, new BasicStroke(3.5f)); plot.setRenderer(renderer); return chart; }
From source file:carfuzzy.Operations.java
public JFreeChart setYAxisForImplication(double imp, XYSeries series, XYSeriesCollection collection, Output out) {/*from w w w . j a va 2s . c om*/ JFreeChart chart; if (out == Output.stop) { series.updateByIndex(0, imp); series.updateByIndex(1, imp); series.updateByIndex(2, imp); } else if (out == Output.speedUp) { series.updateByIndex(1, imp); series.updateByIndex(2, imp); series.updateByIndex(3, imp); } else { series.updateByIndex(1, imp); series.updateByIndex(2, imp); } collection.addSeries(series); String x_axis = "Implication"; chart = XYGraph.drawChart(collection, x_axis, "Membership"); XYPlot plot = chart.getXYPlot(); ValueAxis xaxis = plot.getDomainAxis(); xaxis.setRange(0, 10); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(3.5f)); return chart; }
From source file:wattsup.jsdk.ui.LineChartPanelSupport.java
/** * Sets the color for a series.// w w w . j a v a 2s . co m * * @param serie * The index of a series. It's zero based. * @param color * The color of a series. Might not be <code>null</code>. */ protected void setSeriesPaint(int serie, Color color) { XYItemRenderer localXYItemRenderer = getPlot().getRenderer(); localXYItemRenderer.setSeriesPaint(serie, color); localXYItemRenderer.setSeriesStroke(serie, this.getDefaultLineStroke()); getPlot().setRenderer(localXYItemRenderer); }