List of usage examples for org.jfree.chart.plot XYPlot setDatasetRenderingOrder
public void setDatasetRenderingOrder(DatasetRenderingOrder order)
From source file:be.nbb.demetra.dfm.output.FactorChart.java
private JFreeChart createMarginViewChart() { JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); XYPlot plot = result.getXYPlot(); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); LinesThickness linesThickness = LinesThickness.Thin; XYLineAndShapeRenderer factor = new LineRenderer(FACTOR_INDEX); plot.setRenderer(FACTOR_INDEX, factor); XYLineAndShapeRenderer filtered = new LineRenderer(FILTERED_INDEX); plot.setRenderer(FILTERED_INDEX, filtered); XYDifferenceRenderer difference = new XYDifferenceRenderer(); difference.setAutoPopulateSeriesPaint(false); difference.setAutoPopulateSeriesStroke(false); difference.setBaseStroke(TsCharts.getNormalStroke(linesThickness)); plot.setRenderer(DIFFERENCE_INDEX, difference); DateAxis domainAxis = new DateAxis(); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis);// w w w. j a va 2 s .co m NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); return result; }
From source file:it.cnr.istc.iloc.gui.StateVariableVisualizer.java
@Override public Collection<XYPlot> getPlots(Type type) { Collection<IItem> instances = type.getInstances(); Collection<XYPlot> plots = new ArrayList<>(instances.size()); Map<IItem, Collection<Atom>> sv_atoms = new IdentityHashMap<>(instances.size()); for (IItem i : type.getInstances()) { sv_atoms.put(i, new ArrayList<>()); }/*from ww w . j a va2s.c om*/ for (Atom atom : ((StateVariable) type).getDefinedPredicates().stream() .flatMap(p -> p.getInstances().stream()).map(a -> (Atom) a) .filter(a -> a.state.evaluate().isSingleton() && a.state.evaluate().contains(AtomState.Active)) .collect(Collectors.toList())) { for (IItem i : ((IEnumItem) atom.get(SCOPE)).getEnumVar().evaluate().getAllowedValues()) { if (sv_atoms.containsKey(i)) { sv_atoms.get(i).add(atom); } } } for (IItem sv : instances) { Collection<Atom> atoms = sv_atoms.get(sv); // For each pulse the atoms starting at that pulse Map<Double, Collection<Atom>> starting_atoms = new HashMap<>(atoms.size()); // For each pulse the atoms ending at that pulse Map<Double, Collection<Atom>> ending_atoms = new HashMap<>(atoms.size()); // The pulses of the timeline Set<Double> c_pulses = new HashSet<>(atoms.size() * 2); for (Atom atom : atoms) { double start = sv.getCore().evaluate(((IArithItem) atom.get("start")).getArithVar()); double end = sv.getCore().evaluate(((IArithItem) atom.get("end")).getArithVar()); if (!starting_atoms.containsKey(start)) { starting_atoms.put(start, new ArrayList<>()); } starting_atoms.get(start).add(atom); if (!ending_atoms.containsKey(end)) { ending_atoms.put(end, new ArrayList<>()); } ending_atoms.get(end).add(atom); c_pulses.add(start); c_pulses.add(end); } // we sort current pulses.. Double[] c_pulses_array = c_pulses.toArray(new Double[c_pulses.size()]); Arrays.sort(c_pulses_array); XYIntervalSeriesCollection collection = new XYIntervalSeriesCollection(); ValueXYIntervalSeries undefined = new ValueXYIntervalSeries("Undefined"); ValueXYIntervalSeries sv_values = new ValueXYIntervalSeries("Values"); ValueXYIntervalSeries conflicts = new ValueXYIntervalSeries("Conflicts"); List<Atom> overlapping_atoms = new ArrayList<>(); for (int i = 0; i < c_pulses_array.length - 1; i++) { if (starting_atoms.containsKey(c_pulses_array[i])) { overlapping_atoms.addAll(starting_atoms.get(c_pulses_array[i])); } if (ending_atoms.containsKey(c_pulses_array[i])) { overlapping_atoms.removeAll(ending_atoms.get(c_pulses_array[i])); } switch (overlapping_atoms.size()) { case 0: undefined.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1, new Atom[0]); break; case 1: sv_values.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1, overlapping_atoms.toArray(new Atom[overlapping_atoms.size()])); break; default: conflicts.add(c_pulses_array[i], c_pulses_array[i], c_pulses_array[i + 1], 0, 0, 1, overlapping_atoms.toArray(new Atom[overlapping_atoms.size()])); break; } } collection.addSeries(undefined); collection.addSeries(sv_values); collection.addSeries(conflicts); XYBarRenderer renderer = new XYBarRenderer(); renderer.setSeriesPaint(0, Color.lightGray); renderer.setSeriesPaint(1, new Color(100, 250, 100)); renderer.setSeriesPaint(2, Color.pink); renderer.setBarPainter(new ReverseGradientXYBarPainter()); renderer.setDrawBarOutline(true); renderer.setShadowXOffset(2); renderer.setShadowYOffset(2); renderer.setUseYInterval(true); renderer.setBaseItemLabelsVisible(true); renderer.setBaseItemLabelPaint(Color.black); Font font = new Font("SansSerif", Font.PLAIN, 9); renderer.setBaseItemLabelFont(font); XYItemLabelGenerator generator = (XYDataset dataset, int series, int item) -> toString(((ValueXYIntervalDataItem) ((XYIntervalSeriesCollection) dataset) .getSeries(series).getDataItem(item)).atoms); ItemLabelPosition itLabPos = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); renderer.setBasePositiveItemLabelPosition(itLabPos); for (int i = 0; i < collection.getSeriesCount(); i++) { renderer.setSeriesItemLabelGenerator(i, generator); renderer.setSeriesItemLabelsVisible(i, true); renderer.setSeriesItemLabelPaint(i, Color.black); renderer.setSeriesItemLabelFont(i, font); renderer.setSeriesPositiveItemLabelPosition(i, itLabPos); renderer.setSeriesToolTipGenerator(i, (XYDataset dataset, int series, int item) -> toString( ((ValueXYIntervalDataItem) ((XYIntervalSeriesCollection) dataset).getSeries(series) .getDataItem(item)).atoms)); } XYPlot plot = new XYPlot(collection, null, new NumberAxis(""), renderer); plot.getRangeAxis().setVisible(false); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plots.add(plot); } return plots; }
From source file:ec.ui.view.MarginView.java
private JFreeChart createMarginViewChart() { JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); XYPlot plot = result.getXYPlot(); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); LinesThickness linesThickness = LinesThickness.Thin; XYLineAndShapeRenderer main = new LineRenderer(); plot.setRenderer(MAIN_INDEX, main);/*from w w w . j av a 2 s. c om*/ XYDifferenceRenderer difference = new XYDifferenceRenderer(); difference.setAutoPopulateSeriesPaint(false); difference.setAutoPopulateSeriesStroke(false); difference.setBaseStroke(TsCharts.getNormalStroke(linesThickness)); plot.setRenderer(DIFFERENCE_INDEX, difference); DateAxis domainAxis = new DateAxis(); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); return result; }
From source file:be.nbb.demetra.dfm.output.ConfidenceGraph.java
private JFreeChart createMarginViewChart() { final JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(), PlotOrientation.VERTICAL, false, false, false); result.setPadding(TsCharts.CHART_PADDING); XYPlot plot = result.getXYPlot(); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); XYLineAndShapeRenderer main = new LineRenderer(MAIN_INDEX); plot.setRenderer(MAIN_INDEX, main);//from w w w . jav a 2 s .c o m XYLineAndShapeRenderer original = new LineRenderer(ORIGINAL_DATA_INDEX); plot.setRenderer(ORIGINAL_DATA_INDEX, original); for (int i = 0; i < indexes.length - 1; i++) { plot.setRenderer(indexes[i], getDifferenceRenderer()); for (int j = 1; j < intermediateValues; j++) { plot.setRenderer(indexes[i] - j, getDifferenceRenderer()); } } plot.setRenderer(CONFIDENCE99_INDEX, getDifferenceRenderer()); DateAxis domainAxis = new DateAxis(); domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE); domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setDomainAxis(domainAxis); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAutoRangeIncludesZero(false); rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR); plot.setRangeAxis(rangeAxis); return result; }
From source file:ec.nbdemetra.ui.chart3d.functions.Functions2DChart.java
private JFreeChart createChart() { XYPlot plot = new XYPlot(); plot.setDataset(0, Charts.emptyXYDataset()); plot.setRenderer(0, functionRenderer); plot.mapDatasetToDomainAxis(0, 0);// ww w. java 2s. c o m plot.mapDatasetToRangeAxis(0, 0); plot.setDataset(1, Charts.emptyXYDataset()); plot.setRenderer(1, optimumRenderer); plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); JFreeChart result = new JFreeChart("", TsCharts.CHART_TITLE_FONT, plot, false); LegendTitle legend = new LegendTitle(result.getPlot()); legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0)); legend.setFrame(new LineBorder()); legend.setBackgroundPaint(Color.white); legend.setPosition(RectangleEdge.BOTTOM); result.addLegend(legend); result.setPadding(TsCharts.CHART_PADDING); return result; }
From source file:com.javafxpert.neuralnetviz.scenario.PlotUtil.java
private static JFreeChart createChart(XYZDataset dataset, double[] mins, double[] maxs, int nPoints, XYDataset xyData) {/*from w w w .j av a 2s. c o m*/ NumberAxis xAxis = new NumberAxis("X"); xAxis.setRange(mins[0], maxs[0]); NumberAxis yAxis = new NumberAxis("Y"); yAxis.setRange(mins[1], maxs[1]); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth((maxs[0] - mins[0]) / (nPoints - 1)); renderer.setBlockHeight((maxs[1] - mins[1]) / (nPoints - 1)); PaintScale scale = new GrayPaintScale(0, 1.0); renderer.setPaintScale(scale); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); JFreeChart chart = new JFreeChart("", plot); chart.getXYPlot().getRenderer().setSeriesVisibleInLegend(0, false); NumberAxis scaleAxis = new NumberAxis("Probability (class 0)"); scaleAxis.setAxisLinePaint(Color.white); scaleAxis.setTickMarkPaint(Color.white); scaleAxis.setTickLabelFont(new Font("Dialog", Font.PLAIN, 7)); PaintScaleLegend legend = new PaintScaleLegend(new GrayPaintScale(), scaleAxis); legend.setStripOutlineVisible(false); legend.setSubdivisionCount(20); legend.setAxisLocation(AxisLocation.BOTTOM_OR_LEFT); legend.setAxisOffset(5.0); legend.setMargin(new RectangleInsets(5, 5, 5, 5)); legend.setFrame(new BlockBorder(Color.red)); legend.setPadding(new RectangleInsets(10, 10, 10, 10)); legend.setStripWidth(10); legend.setPosition(RectangleEdge.LEFT); chart.addSubtitle(legend); ChartUtilities.applyCurrentTheme(chart); plot.setDataset(1, xyData); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setBaseLinesVisible(false); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
From source file:charts.Chart.java
public static void ScatterPlot(XYSeriesCollection dataset, String title, String xAxisLabel, String yAxisLabel) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator(); XYURLGenerator urlGenerator = new StandardXYURLGenerator(); XYItemRenderer renderer = new XYLineAndShapeRenderer(false, true);//(boolean lines, boolean shapes) renderer.setBaseToolTipGenerator(toolTipGenerator); renderer.setURLGenerator(urlGenerator); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); //plot.setDataset(dataset); //plot.setDomainAxis(xAxis); //plot.setRangeAxis(yAxis); //plot.setRenderer(renderer); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);//true==legend //INVERTER AS CORES DOS PONTOS E LEGENDA. if (dataset.getSeriesCount() > 1) { Shape s0 = plot.getLegendItems().get(0).getShape(); Shape s1 = plot.getLegendItems().get(1).getShape(); renderer.setSeriesShape(0, s1);// w w w .jav a 2s . co m renderer.setSeriesShape(1, s0); Paint p0 = plot.getLegendItems().get(0).getLinePaint(); Paint p1 = plot.getLegendItems().get(1).getLinePaint(); renderer.setSeriesPaint(0, p1); renderer.setSeriesPaint(1, p0); } //FIM DA INVERSAO. JFrame chartwindow = new JFrame(title); JPanel jpanel = new ChartPanel(chart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }
From source file:OAT.ui.BarChartFrame.java
public void addDataset(ChartDataset dataset) { if (dataset == null || dataset.getSeriesCount() == 0) { return;//from ww w .j a va2 s .c o m } XYPlot plot = getChart().getXYPlot(); int i = plot.getDatasetCount(); for (int j = 0; j < i; j++) { if (plot.getDataset(j).equals(dataset)) { // System.out.println("eq " + i // + " " + ((ChartDataset) plot.getDataset(j)).getTitle() // + " " + dataset.getTitle()); return; } } plot.setDataset(i, dataset); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); Double[] range = dataset.getAxisRange(); //axis int axisId = 0; if (range != null) { // if (range == null || range.length < 2) { // plot.mapDatasetToRangeAxis(i, 0); // } else { //scan for equal axis range, reuse if found boolean hasSameRange = false; if (range.length > 1) { for (int j = 1; j < plot.getRangeAxisCount(); j++) { Range otherRange = plot.getRangeAxis(j).getRange(); if (otherRange != null && otherRange.getLowerBound() == range[0] && otherRange.getUpperBound() == range[1]) { axisId = j; hasSameRange = true; break; } } } if (!hasSameRange) { NumberAxis newAxis = new NumberAxis(); if (range.length > 1) { newAxis.setAutoRange(false); newAxis.setRange(range[0], range[1]); } if (range.length > 2) { newAxis.setAutoTickUnitSelection(false, false); newAxis.setTickUnit(new NumberTickUnit(range[2])); } newAxis.setNumberFormatOverride(TextUtil.SIMPLE_FORMATTER); // newAxis.setAxisLinePaint(new Color(100, 0, 0)); // newAxis.setLabelPaint(paints[i][0]); // newAxis.setTickLabelPaint(paints[i][0]); // newAxis.setTickMarkPaint(paints[i][0]); // newAxis.setTickLabelsVisible(true); axisId = plot.getRangeAxisCount(); plot.setRangeAxis(axisId, newAxis, false); plot.setRangeAxisLocation(axisId, AxisLocation.BOTTOM_OR_LEFT, false); } // plot.mapDatasetToRangeAxis(i, newAxisId); } plot.mapDatasetToRangeAxis(i, axisId); // //renderer XYLineAndShapeRenderer renderer; if (dataset instanceof TradeDataset) { renderer = new TradeRenderer(); for (int j = 0; j < dataset.getSeriesCount(); j++) { renderer.setSeriesLinesVisible(j, false); } } else { Shape shape = Main.defaultShape; Paint[][] seriesPaints; Stroke stroke; if (dataset.getSource() instanceof Stopper && !(dataset.getSource() instanceof Calculator)) { seriesPaints = Main.greyPaints; stroke = Main.dottedStoke; } else { seriesPaints = Main.defaultPaints; stroke = Main.defaultStoke; } renderer = new IndicatorRenderer(seriesPaints[(i - 1) % seriesPaints.length], shape, stroke); } plot.setRenderer(i, renderer, false); }
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);/* ww w . j av a2 s . c om*/ 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:playground.thibautd.utils.charts.BoxAndWhiskersChart.java
private void createChart() { boolean legend = false; this.createDataSet(); this.chart = ChartFactory.createBoxAndWhiskerChart(this.chartTitle, this.xAxisLabel, this.yAxisLabel, this.boxes, legend); XYPlot plot = this.chart.getXYPlot(); plot.setDomainAxis(new NumberAxis(this.xAxisLabel)); plot.getDomainAxis().configure();//from w ww. ja v a2 s . com if (plotStdDev) { XYErrorRenderer renderer = new XYErrorRenderer(); // in black renderer.setErrorPaint(Color.BLACK); // only plot Y error renderer.setDrawXError(false); // do not render average (already done by the B&W) renderer.setBaseShapesVisible(false); plot.setRenderer(1, renderer); plot.setDataset(1, deviationBars); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); } //this.addMatsimLogo(); //try { // this.addDefaultFormatting(); //} catch (NullPointerException e) { // // occurs if no legend //} //this.chart.setBackgroundPaint(Color.white); plot.setBackgroundPaint(Color.white); XYBoxAndWhiskerRenderer renderer = (XYBoxAndWhiskerRenderer) plot.getRenderer(); //renderer.setFillBox(false); //renderer.setSeriesOutlinePaint(0, Color.black); //renderer.setSeriesPaint(0, Color.black); renderer.setBoxPaint(renderer.getSeriesPaint(0)); //auto-adjust renderer.setBoxWidth(-1); }