List of usage examples for org.jfree.chart.plot XYPlot setRangeGridlinesVisible
public void setRangeGridlinesVisible(boolean visible)
From source file:wattsup.jsdk.ui.ChartPanelSupport.java
/** * Clean the values of the chart./* w w w . ja v a 2s . co m*/ * * @see #createChart() */ public void cleanChart() { this.chart_.removeLegend(); this.chartPanel_.setBorder(null); cleanLabels(); DateAxis localDateAxis = (DateAxis) ((XYPlot) this.chart_.getPlot()).getDomainAxis(); localDateAxis.setTickLabelsVisible(false); localDateAxis.setTickMarksVisible(false); localDateAxis.setAxisLineVisible(false); ValueAxis localValueAxis = ((XYPlot) this.chart_.getPlot()).getRangeAxis(); localValueAxis.setTickLabelsVisible(false); localValueAxis.setTickMarksVisible(false); localValueAxis.setAxisLineVisible(false); XYPlot localXYPlot = (XYPlot) this.chart_.getPlot(); localXYPlot.setDomainGridlineStroke(this.defaultLineStroke_); localXYPlot.setDomainGridlinesVisible(true); localXYPlot.setRangeGridlineStroke(this.defaultLineStroke_); localXYPlot.setRangeGridlinesVisible(true); localXYPlot.setAxisOffset(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D)); localXYPlot.setInsets(new RectangleInsets(0.0D, 0.0D, 0.0D, 0.0D), true); }
From source file:asl.util.PlotMaker2.java
public void writePlot(String fileName) { //System.out.format("== plotTitle=[%s] fileName=[%s]\n", plotTitle, fileName); File outputFile = new File(fileName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format("== plotMaker: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", fileName); return;/*from w ww.j a va 2 s. c o m*/ } NumberAxis horizontalAxis = new NumberAxis("x-axis default"); // x = domain if (fileName.contains("nlnm") || fileName.contains("coher") || fileName.contains("stn")) { // NLNM or StationDeviation horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(1, 11000)); horizontalAxis.setTickUnit(new NumberTickUnit(5.0)); } else { // EventCompareSynthetics/StrongMotion horizontalAxis = new NumberAxis("Time (s)"); double x[] = panels.get(0).getTraces().get(0).getxData(); horizontalAxis.setRange(new Range(x[0], x[x.length - 1])); } CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.setGap(15.); // Loop over (3) panels for this plot: for (Panel panel : panels) { NumberAxis verticalAxis = new NumberAxis("y-axis default"); // y = range if (fileName.contains("nlnm") || fileName.contains("stn")) { // NLNM or StationDeviation verticalAxis = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB"); verticalAxis.setRange(new Range(-190, -95)); verticalAxis.setTickUnit(new NumberTickUnit(5.0)); } else if (fileName.contains("coher")) { // Coherence verticalAxis = new NumberAxis("Coherence, Gamma"); verticalAxis.setRange(new Range(0, 1.2)); verticalAxis.setTickUnit(new NumberTickUnit(0.1)); } else { // EventCompareSynthetics/StrongMotion verticalAxis = new NumberAxis("Displacement (m)"); } Font fontPlain = new Font("Verdana", Font.PLAIN, 14); Font fontBold = new Font("Verdana", Font.BOLD, 18); verticalAxis.setLabelFont(fontBold); verticalAxis.setTickLabelFont(fontPlain); horizontalAxis.setLabelFont(fontBold); horizontalAxis.setTickLabelFont(fontPlain); XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); // Plot each trace on this panel: int iTrace = 0; for (Trace trace : panel.getTraces()) { XYSeries series = new XYSeries(trace.getName()); double xdata[] = trace.getxData(); double ydata[] = trace.getyData(); for (int k = 0; k < xdata.length; k++) { series.add(xdata[k], ydata[k]); } renderer.setSeriesPaint(iTrace, trace.getColor()); renderer.setSeriesStroke(iTrace, trace.getStroke()); renderer.setSeriesLinesVisible(iTrace, true); renderer.setSeriesShapesVisible(iTrace, false); seriesCollection.addSeries(series); iTrace++; } // Add Annotations for each trace - This is done in a separate loop so that // the upper/lower limits for this panel will be known double xmin = horizontalAxis.getRange().getLowerBound(); double xmax = horizontalAxis.getRange().getUpperBound(); double ymin = verticalAxis.getRange().getLowerBound(); double ymax = verticalAxis.getRange().getUpperBound(); double delX = Math.abs(xmax - xmin); double delY = Math.abs(ymax - ymin); // Annotation (x,y) in normalized units - where upper-right corner = (1,1) double xAnn = 0.97; // Right center coords of the trace name (e.g., "00-LHZ") double yAnn = 0.95; double yOff = 0.05; // Vertical distance between different trace legends iTrace = 0; for (Trace trace : panel.getTraces()) { if (!trace.getName().contains("NLNM") && !trace.getName().contains("NHNM")) { // x1 > x2 > x3, e.g.: // o-------o 00-LHZ // x3 x2 x1 double scale = .01; // Controls distance between trace label and line segment double xL = .04; // Length of trace line segment in legend double xAnn2 = xAnn - scale * trace.getName().length(); double xAnn3 = xAnn - scale * trace.getName().length() - xL; double x1 = xAnn * delX + xmin; // Right hand x-coord of text in range units double x2 = xAnn2 * delX + xmin; // x-coord of line segment end in range units double x3 = xAnn3 * delX + xmin; // x-coord of line segment end in range units double y = (yAnn - (iTrace * yOff)) * delY + ymin; if (horizontalAxis instanceof LogarithmicAxis) { double logMin = Math.log10(xmin); double logMax = Math.log10(xmax); delX = logMax - logMin; x1 = Math.pow(10, xAnn * delX + logMin); x2 = Math.pow(10, xAnn2 * delX + logMin); x3 = Math.pow(10, xAnn3 * delX + logMin); } xyplot.addAnnotation(new XYLineAnnotation(x3, y, x2, y, trace.getStroke(), trace.getColor())); XYTextAnnotation xyText = new XYTextAnnotation(trace.getName(), x1, y); xyText.setFont(new Font("Verdana", Font.BOLD, 18)); xyText.setTextAnchor(TextAnchor.CENTER_RIGHT); xyplot.addAnnotation(xyText); } iTrace++; } combinedPlot.add(xyplot, 1); } // panel final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle, new Font("Verdana", Font.BOLD, 18))); chart.removeLegend(); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 1400); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }
From source file:asl.plotmaker.PlotMaker2.java
public void writePlot(String fileName) { // System.out.format("== plotTitle=[%s] fileName=[%s]\n", plotTitle, // fileName); File outputFile = new File(fileName); // Check that we will be able to output the file without problems and if // not --> return if (!checkFileOut(outputFile)) { // System.out.format("== plotMaker: request to output plot=[%s] but we are unable to create it " // + " --> skip plot\n", fileName ); logger.warn("== Request to output plot=[{}] but we are unable to create it " + " --> skip plot\n", fileName);//from w w w . j a va2s .co m return; } NumberAxis horizontalAxis = new NumberAxis("x-axis default"); // x = // domain if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("coher") || fileName.contains("stn")) { // NLNM or StationDeviation horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(1, 11000)); horizontalAxis.setTickUnit(new NumberTickUnit(5.0)); } else { // EventCompareSynthetics/StrongMotion horizontalAxis = new NumberAxis("Time (s)"); double x[] = panels.get(0).getTraces().get(0).getxData(); horizontalAxis.setRange(new Range(x[0], x[x.length - 1])); } CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(horizontalAxis); combinedPlot.setGap(15.); // Loop over (3) panels for this plot: for (Panel panel : panels) { NumberAxis verticalAxis = new NumberAxis("y-axis default"); // y = // range if (fileName.contains("alnm") || fileName.contains("nlnm") || fileName.contains("stn")) { // NLNM // or // StationDeviation verticalAxis = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB"); verticalAxis.setRange(new Range(-190, -80)); verticalAxis.setTickUnit(new NumberTickUnit(5.0)); } else if (fileName.contains("coher")) { // Coherence verticalAxis = new NumberAxis("Coherence, Gamma"); verticalAxis.setRange(new Range(0, 1.2)); verticalAxis.setTickUnit(new NumberTickUnit(0.1)); } else { // EventCompareSynthetics/StrongMotion verticalAxis = new NumberAxis("Displacement (m)"); } Font fontPlain = new Font("Verdana", Font.PLAIN, 14); Font fontBold = new Font("Verdana", Font.BOLD, 18); verticalAxis.setLabelFont(fontBold); verticalAxis.setTickLabelFont(fontPlain); horizontalAxis.setLabelFont(fontBold); horizontalAxis.setTickLabelFont(fontPlain); XYSeriesCollection seriesCollection = new XYSeriesCollection(); XYDotRenderer renderer = new XYDotRenderer(); XYPlot xyplot = new XYPlot(seriesCollection, horizontalAxis, verticalAxis, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); // Plot each trace on this panel: int iTrace = 0; for (Trace trace : panel.getTraces()) { XYSeries series = new XYSeries(trace.getName()); double xdata[] = trace.getxData(); double ydata[] = trace.getyData(); for (int k = 0; k < xdata.length; k++) { series.add(xdata[k], ydata[k]); } renderer.setSeriesPaint(iTrace, trace.getColor()); renderer.setSeriesStroke(iTrace, trace.getStroke()); seriesCollection.addSeries(series); iTrace++; } // Add Annotations for each trace - This is done in a separate loop // so that // the upper/lower limits for this panel will be known double xmin = horizontalAxis.getRange().getLowerBound(); double xmax = horizontalAxis.getRange().getUpperBound(); double ymin = verticalAxis.getRange().getLowerBound(); double ymax = verticalAxis.getRange().getUpperBound(); double delX = Math.abs(xmax - xmin); double delY = Math.abs(ymax - ymin); // Annotation (x,y) in normalized units - where upper-right corner = // (1,1) double xAnn = 0.97; // Right center coords of the trace name (e.g., // "00-LHZ") double yAnn = 0.95; double yOff = 0.05; // Vertical distance between different trace // legends iTrace = 0; for (Trace trace : panel.getTraces()) { if (!trace.getName().contains("NLNM") && !trace.getName().contains("NHNM") && !trace.getName().contains("ALNM")) { // x1 > x2 > x3, e.g.: // o-------o 00-LHZ // x3 x2 x1 double scale = .01; // Controls distance between trace label // and line segment double xL = .04; // Length of trace line segment in legend double xAnn2 = xAnn - scale * trace.getName().length(); double xAnn3 = xAnn - scale * trace.getName().length() - xL; double x1 = xAnn * delX + xmin; // Right hand x-coord of // text in range units double x2 = xAnn2 * delX + xmin; // x-coord of line segment // end in range units double x3 = xAnn3 * delX + xmin; // x-coord of line segment // end in range units double y = (yAnn - (iTrace * yOff)) * delY + ymin; if (horizontalAxis instanceof LogarithmicAxis) { double logMin = Math.log10(xmin); double logMax = Math.log10(xmax); delX = logMax - logMin; x1 = Math.pow(10, xAnn * delX + logMin); x2 = Math.pow(10, xAnn2 * delX + logMin); x3 = Math.pow(10, xAnn3 * delX + logMin); } xyplot.addAnnotation(new XYLineAnnotation(x3, y, x2, y, trace.getStroke(), trace.getColor())); XYTextAnnotation xyText = new XYTextAnnotation(trace.getName(), x1, y); xyText.setFont(new Font("Verdana", Font.BOLD, 18)); xyText.setTextAnchor(TextAnchor.CENTER_RIGHT); xyplot.addAnnotation(xyText); } iTrace++; } combinedPlot.add(xyplot, 1); } // panel final JFreeChart chart = new JFreeChart(combinedPlot); chart.setTitle(new TextTitle(plotTitle, new Font("Verdana", Font.BOLD, 18))); chart.removeLegend(); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 1400, 1400); } catch (IOException e) { // System.err.println("Problem occurred creating chart."); logger.error("IOException:", e); } }
From source file:GraphUI.java
/** * Creates new form GraphUI/*from w w w. j a v a2 s. c o m*/ */ public GraphUI() { try { //graphPane is the jPanel in the jFrame //cp is the ChartPanel that needs to be held inside jPanel1 initComponents(); data = Pinwheel.getData(); this.batch = data[0]; //jPanel1 = createChartPanel(); cp = createChartPanel(); //cp = new ChartPanel(chart); cp.setMouseWheelEnabled(true); jPanel1.add(cp); XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesStroke(0, new BasicStroke(3.0f)); renderer.setSeriesStroke(1, new BasicStroke(3.0f)); plot.setBackgroundPaint(Color.DARK_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); plot.setRenderer(renderer); this.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { backBtn.doClick(); } }); } catch (SQLException ex) { Logger.getLogger(GraphUI.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.gumtree.vis.awt.PlotFactory.java
public static JFreeChart createXYErrorChart(IXYErrorDataset dataset) { JFreeChart chart;/*from www. j a va 2 s.co m*/ String title = null; String xTitle = null; String yTitle = null; if (dataset != null) { title = ""; if (dataset.getTitle() != null) { title = dataset.getTitle(); } xTitle = ""; if (dataset.getXTitle() != null) { xTitle += dataset.getXTitle(); } if (dataset.getXUnits() != null) { xTitle += " (" + dataset.getXUnits() + ")"; } yTitle = ""; if (dataset.getYTitle() != null) { yTitle += dataset.getYTitle(); } if (dataset.getYUnits() != null) { yTitle += " (" + dataset.getYUnits() + ")"; } } else { dataset = new XYErrorDataset(); } chart = createXYLineChart(title, xTitle, yTitle, dataset, PlotOrientation.VERTICAL, true, false, true); chart.setBackgroundPaint(Color.WHITE); final LegendTitle legend = (LegendTitle) chart.getLegend(); RectangleEdge legendPosition = RectangleEdge.BOTTOM; try { String legendProperty = "RectangleEdge." + System.getProperty("kuranda1D.legendPosition"); if (RectangleEdge.BOTTOM.toString().equals(legendProperty)) legendPosition = RectangleEdge.BOTTOM; else if (RectangleEdge.RIGHT.toString().equals(legendProperty)) legendPosition = RectangleEdge.RIGHT; else if (RectangleEdge.LEFT.toString().equals(legendProperty)) legendPosition = RectangleEdge.LEFT; else if (RectangleEdge.TOP.toString().equals(legendProperty)) legendPosition = RectangleEdge.TOP; } catch (Exception e) { // TODO: handle exception } legend.setPosition(legendPosition); chart.setBorderVisible(true); // ChartUtilities.applyCurrentTheme(chart); // chartTheme.apply(chart); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); // plot.setRangeZeroBaselineVisible(false); // plot.setDomainZeroBaselineVisible(false); ValueAxis rangeAxis = plot.getRangeAxis(); if (rangeAxis instanceof NumberAxis) { ((NumberAxis) rangeAxis).setAutoRangeStickyZero(false); ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(false); } ValueAxis domainAxis = plot.getDomainAxis(); if (domainAxis instanceof NumberAxis) { ((NumberAxis) domainAxis).setAutoRangeStickyZero(false); ((NumberAxis) domainAxis).setAutoRangeIncludesZero(false); } plot.setDomainPannable(true); plot.setRangePannable(true); plot.setDomainGridlinesVisible(true); // plot.setDomainCrosshairLockedOnData(true); // plot.setDomainCrosshairVisible(true); plot.setRangeGridlinesVisible(true); // plot.setRangeCrosshairLockedOnData(true); // plot.setRangeCrosshairVisible(true); // xAxis = plot.getDomainAxis(); // yAxis = plot.getRangeAxis(); plot.setDataset(dataset); XYItemRenderer renderer = chart.getXYPlot().getRenderer(); if (renderer instanceof XYErrorRenderer) { // ((XYLineAndShapeRenderer) renderer).setBaseShapesVisible(true); ((XYErrorRenderer) renderer).setBaseShapesFilled(true); ((XYErrorRenderer) renderer).setDrawXError(false); ((XYErrorRenderer) renderer).setDrawYError(true); } chart.fireChartChanged(); return chart; }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java
private void buildMainChart(String title, String subTitle, String xAxisLabel, String yAxisLabel, String fileName) {/*www . j av a 2 s. co m*/ final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createMatrixDataSet()); final JFreeChart chart = ChartFactory.createBubbleChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); chart.addSubtitle(new TextTitle(subTitle)); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE)); chart.removeLegend(); // Perform customizations starts here ... final XYPlot plot1 = chart.getXYPlot(); plot1.setDomainGridlinesVisible(false); plot1.setRangeGridlinesVisible(false); plot1.setForegroundAlpha(0.5f); plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel())); plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel())); // Custumize the domain axis ( y ) final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setRange(-1, this.array.length); // Custumize the range axis ( y ) final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(-1, this.array.length); // Create custom renderer StandardXYItemRenderer ren = new CustomRenderer(false); ren.setSeriesItemLabelPaint(0, Color.BLACK); plot1.setRenderer(ren); this.mainChart = chart; }
From source file:de.citec.csra.allocation.vis.MovingChart.java
/** * Creates a sample chart.// w ww .ja v a 2s. c om * * @param dataset the dataset. * * @return A sample chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart result = ChartFactory.createTimeSeriesChart(null, "Time", "Resource", dataset, false, true, false); final XYPlot plot = result.getXYPlot(); plot.addDomainMarker(this.marker); plot.setBackgroundPaint(new Color(0xf8f8ed)); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.lightGray); ValueAxis xaxis = plot.getDomainAxis(); xaxis.setAutoRange(true); xaxis.setTickLabelsVisible(false); //Domain axis would show data of 60 seconds for a time xaxis.setFixedAutoRange(this.past + this.future); // 60 seconds xaxis.setVerticalTickLabels(true); ValueAxis yaxis = plot.getRangeAxis(); yaxis.setAutoRangeMinimumSize(1.8); yaxis.setAutoRange(true); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setTickUnit(new NumberTickUnit(1)); range.setNumberFormatOverride(new NumberFormat() { @Override public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) { return format((long) number, toAppendTo, pos); } private String getID(long number) { return values.entrySet().stream().filter(e -> e.equals(number)).findFirst().get().getKey(); } @Override public StringBuffer format(long number, StringBuffer ap, FieldPosition pos) { String id = "N/A"; if (number == 0) { id = "(Time)"; } if (values.containsValue(number)) { for (Map.Entry<String, Long> entry : values.entrySet()) { if (entry.getValue() == number) { id = entry.getKey(); break; } } } id = id.replaceFirst("/$", ""); ap.append(id); if (id.length() > 32) { ap.replace(15, ap.length() - 15, ".."); } return ap; } @Override public Number parse(String source, ParsePosition parsePosition) { return null; } }); // this.chart.getXYPlot().getRenderer(1).set // XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) this.chart.getXYPlot().getRendererForDataset(dataset); return result; }
From source file:net.nosleep.superanalyzer.analysis.views.YearView.java
private void createChart() { NumberAxis xAxis = new NumberAxis(Misc.getString("RELEASE_YEAR")); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(Misc.getString("SONG_COUNT")); yAxis.setAutoRangeIncludesZero(true); xAxis.setNumberFormatOverride(new DecimalFormat("0")); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); XYPlot plot = new XYPlot(_dataset, xAxis, yAxis, renderer); // create and return the chart panel... _chart = new JFreeChart(Misc.getString("RELEASE_YEAR"), JFreeChart.DEFAULT_TITLE_FONT, plot, true); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setAxisOffset(new RectangleInsets(4, 4, 4, 4)); LegendTitle legend = _chart.getLegend(); legend.setFrame(BlockBorder.NONE);// www .j a v a 2 s . co m _chart.addSubtitle(HomePanel.createSubtitle(Misc.getString("RELEASE_YEAR_TOOLTIP"))); XYToolTipGenerator generator = new StandardXYToolTipGenerator("{2}", new DecimalFormat("0.00"), new DecimalFormat("0.00")); renderer.setToolTipGenerator(generator); ChartUtilities.applyCurrentTheme(_chart); // format the lines after applying the theme renderer.setBaseShapesVisible(true); renderer.setDrawOutlines(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); renderer.setSeriesStroke(0, new BasicStroke(3.0f)); renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f)); renderer.setSeriesShape(0, new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0)); renderer.setSeriesStroke(1, new BasicStroke(3.0f)); renderer.setSeriesOutlineStroke(1, new BasicStroke(2.0f)); renderer.setSeriesShape(1, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0)); _chart.setPadding(new RectangleInsets(10, 10, 10, 10)); Misc.formatChart(plot); }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java
private void buildLegendChart(int nbValues) { this.legendValues = new int[nbValues + 1]; this.legendValues[0] = 0; int offset = 255 / nbValues; int step = offset; if (this.scaleMode == Chart.Scale.LOGARITHMIC) { double logStep = (Math.log(this.maxValue) / Math.log(2)) / nbValues; for (int i = 1; i < (nbValues + 1); i++) { this.legendValues[i] = (int) Math.pow(2, logStep * i); }/*from ww w. j ava 2 s. c om*/ } else { // Linear scale mode for (int i = 1; i < (nbValues + 1); i++) { this.legendValues[i] = (step * this.maxValue) / 255; step += offset; } } final MatrixSeriesCollection dataset = new MatrixSeriesCollection(this.createLegendDataSet()); final JFreeChart chart = ChartFactory.createBubbleChart("", "", "", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.WHITE)); chart.removeLegend(); // Perform customizations starts here ... final XYPlot plot1 = chart.getXYPlot(); plot1.setDomainGridlinesVisible(false); plot1.setRangeGridlinesVisible(false); plot1.setForegroundAlpha(0.5f); plot1.setDomainAxis(new CustomAxis(plot1.getDomainAxis().getLabel())); plot1.setRangeAxis(new CustomAxis(plot1.getRangeAxis().getLabel())); // Custumize the domain axis ( x ) final NumberAxis domainAxis = (NumberAxis) plot1.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); domainAxis.setRange(-1, 1); domainAxis.setVisible(false); // Custumize the range axis ( y ) final NumberAxis rangeAxis = (NumberAxis) plot1.getRangeAxis(); rangeAxis.setTickUnit(new CustomTickUnit(rangeAxis.getTickUnit().getSize())); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(-1, this.legendValues.length); rangeAxis.setTickLabelsVisible(true); rangeAxis.setTickMarkInsideLength(4); // Create custom renderer StandardXYItemRenderer ren = new CustomRenderer(true); ren.setSeriesItemLabelPaint(0, Color.BLUE); plot1.setRenderer(ren); plot1.setRangeAxisLocation(AxisLocation.TOP_OR_RIGHT); this.legendChart = chart; }
From source file:wef.articulab.view.ui.CombinedBNXYPlot.java
private XYPlot createPlot(ChartContainer chartContainer) { createDataset(chartContainer);/*from www. j a v a 2 s. c o m*/ chartContainer.target = new IntervalMarker(14, 16); chartContainer.target.setLabel("Activation Threshold"); chartContainer.target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11)); chartContainer.target.setLabelAnchor(RectangleAnchor.LEFT); chartContainer.target.setLabelTextAnchor(TextAnchor.CENTER_LEFT); chartContainer.target.setPaint(new Color(222, 222, 255, 128)); XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false); BasicStroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); for (int i = 0; i < chartContainer.series.length - 1; i++) { renderer.setSeriesStroke(i, stroke); } renderer.setSeriesStroke(chartContainer.series.length - 1, new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f)); NumberAxis rangeAxis = new NumberAxis("Activation"); NumberAxis domainAxis = new NumberAxis("Time"); XYPlot plot = new XYPlot(chartContainer.dataset, domainAxis, rangeAxis, renderer); plot.addRangeMarker(chartContainer.target, Layer.BACKGROUND); plot.setRenderer(renderer); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); plot.setRangeGridlinesVisible(true); plot.setBackgroundPaint(Color.LIGHT_GRAY); chartContainer.plot = plot; return plot; }