List of usage examples for org.jfree.chart.plot XYPlot setDomainMinorGridlinePaint
public void setDomainMinorGridlinePaint(Paint paint)
From source file:clientv2.GUI.java
/** * Creates a chart/*from w w w .j a va2 s. c o m*/ * * @param TS * @param GraphName * @return */ public JFreeChart createChart(TimeSeriesCollection TS, String GraphName, double minRange, double maxRange) { JFreeChart chart = ChartFactory.createTimeSeriesChart(GraphName, "Time", "Value", TS, true, true, false); final XYPlot plot = chart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); plot.getRangeAxis().setRange(minRange, maxRange); plot.setBackgroundPaint(WHITE); plot.setDomainMinorGridlinePaint(BLACK); plot.setDomainGridlinePaint(BLACK); plot.setRangeMinorGridlinePaint(BLACK); plot.setRangeGridlinesVisible(true); axis.setFixedAutoRange(20000.0); return chart; }
From source file:org.gwaspi.gui.reports.SampleQAHetzygPlotZoom.java
private JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createScatterPlot("Heterozygosity vs. Missing Ratio", "Heterozygosity Ratio", "Missing Ratio", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); // CHART BACKGROUD COLOR chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness plot.setBackgroundPaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9 // GRIDLINES//from w w w.j ava2 s.co m plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f)); plot.setDomainGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7 plot.setDomainMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND); // Hue, saturation, brightness 9 plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker().darker()); // Hue, saturation, brightness 7 plot.setRangeMinorGridlinePaint(PLOT_MANHATTAN_BACKGROUND.darker()); // Hue, saturation, brightness 8 plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); // DOTS RENDERER XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, PLOT_MANHATTAN_DOTS); // renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY); // renderer.setUseOutlinePaint(true); // Set dot shape of the currently appended Series renderer.setSeriesShape(0, new Rectangle2D.Double(-1, -1, 2, 2)); renderer.setSeriesVisibleInLegend(0, false); // AXIS double maxHetzy = 0.005; for (int i = 0; i < dataset.getItemCount(0); i++) { if (maxHetzy < dataset.getXValue(0, i)) { maxHetzy = dataset.getXValue(0, i); } } NumberAxis hetzyAxis = (NumberAxis) plot.getDomainAxis(); hetzyAxis.setAutoRangeIncludesZero(true); hetzyAxis.setAxisLineVisible(true); hetzyAxis.setTickLabelsVisible(true); hetzyAxis.setTickMarksVisible(true); hetzyAxis.setRange(0, maxHetzy * 1.1); double maxMissrat = 0.005; for (int i = 0; i < dataset.getItemCount(0); i++) { if (maxMissrat < dataset.getYValue(0, i)) { maxMissrat = dataset.getYValue(0, i); } } NumberAxis missratAxis = (NumberAxis) plot.getRangeAxis(); missratAxis.setAutoRangeIncludesZero(true); missratAxis.setAxisLineVisible(true); missratAxis.setTickLabelsVisible(true); missratAxis.setTickMarksVisible(true); missratAxis.setRange(0, maxMissrat * 1.1); // Add significance Threshold to subplot final Marker missingThresholdLine = new ValueMarker(missingThreshold); missingThresholdLine.setPaint(Color.blue); final Marker hetzyThresholdLine = new ValueMarker(hetzyThreshold); hetzyThresholdLine.setPaint(Color.blue); // Add legend to hetzyThreshold hetzyThresholdLine.setLabel("hetzyg. threshold = " + hetzyThreshold); missingThresholdLine.setLabel("missing. threshold = " + missingThreshold); hetzyThresholdLine.setLabelAnchor(RectangleAnchor.TOP_LEFT); hetzyThresholdLine.setLabelTextAnchor(TextAnchor.TOP_RIGHT); missingThresholdLine.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); missingThresholdLine.setLabelTextAnchor(TextAnchor.TOP_LEFT); plot.addRangeMarker(missingThresholdLine); // THIS FOR MISSING RATIO plot.addDomainMarker(hetzyThresholdLine); // THIS FOR HETZY RATIO // Marker label if below hetzyThreshold XYItemRenderer lblRenderer = plot.getRenderer(); // THRESHOLD AND SELECTED LABEL GENERATOR MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(hetzyThreshold, missingThreshold); lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator); lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 10)); lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BOTTOM_LEFT, TextAnchor.BOTTOM_LEFT, 2 * Math.PI)); // TOOLTIP GENERATOR MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator(); lblRenderer.setBaseToolTipGenerator(tooltipGenerator); lblRenderer.setSeriesItemLabelsVisible(0, true); return chart; }
From source file:org.gwaspi.gui.reports.ManhattanPlotZoom.java
private JFreeChart createChart(XYDataset dataset, ChromosomeKey chr) { JFreeChart chart = ChartFactory.createScatterPlot(null, "", "P value", dataset, PlotOrientation.VERTICAL, true, false, false);/*w ww .j a v a2 s. c o m*/ XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); // CHART BACKGROUD COLOR chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness plot.setBackgroundPaint(manhattan_back); // Hue, saturation, brightness 9 // GRIDLINES plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f)); plot.setDomainGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7 plot.setDomainMinorGridlinePaint(manhattan_back); // Hue, saturation, brightness 9 plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7 plot.setRangeMinorGridlinePaint(manhattan_back.darker()); // Hue, saturation, brightness 8 plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); // DOTS RENDERER XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesPaint(0, manhattan_dot); // renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY); // renderer.setUseOutlinePaint(true); // Set dot shape of the currently appended Series renderer.setSeriesShape(0, new Rectangle2D.Double(0.0, 0.0, 2, 2)); renderer.setSeriesVisibleInLegend(0, false); NumberAxis positionAxis = (NumberAxis) plot.getDomainAxis(); // domainAxis.setAutoRangeIncludesZero(false); // domainAxis.setTickMarkInsideLength(2.0f); // domainAxis.setTickMarkOutsideLength(2.0f); // domainAxis.setMinorTickCount(2); // domainAxis.setMinorTickMarksVisible(true); positionAxis.setLabelAngle(1.0); positionAxis.setAutoRangeIncludesZero(false); positionAxis.setAxisLineVisible(true); positionAxis.setTickLabelsVisible(true); positionAxis.setTickMarksVisible(true); // ADD INVERSE LOG(10) Y AXIS LogAxis logPAxis = new LogAxis("P value"); logPAxis.setBase(10); logPAxis.setInverted(true); logPAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE); logPAxis.setTickMarkOutsideLength(2.0f); logPAxis.setMinorTickCount(2); logPAxis.setMinorTickMarksVisible(true); logPAxis.setAxisLineVisible(true); logPAxis.setUpperMargin(0); TickUnitSource units = NumberAxis.createIntegerTickUnits(); logPAxis.setStandardTickUnits(units); plot.setRangeAxis(0, logPAxis); // Add significance Threshold to subplot //threshold = 0.5/rdMatrixMetadata.getMarkerSetSize(); // (0.05/10? SNPs => 5*10-?) final Marker thresholdLine = new ValueMarker(threshold); thresholdLine.setPaint(Color.red); // Add legend to threshold thresholdLine.setLabel("P = " + GenericReportGenerator.FORMAT_P_VALUE.format(threshold)); thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT); thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); plot.addRangeMarker(thresholdLine); // Marker label if below threshold XYItemRenderer lblRenderer = plot.getRenderer(); // THRESHOLD AND SELECTED LABEL GENERATOR MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(threshold, chr); lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator); lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 12)); lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_LEFT, Math.PI / 4.0)); // TOOLTIP GENERATOR MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator(chr); lblRenderer.setBaseToolTipGenerator(tooltipGenerator); lblRenderer.setSeriesItemLabelsVisible(0, true); return chart; }
From source file:de.atomfrede.tools.evalutation.tools.plot.TimePlot.java
@Override protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) { XYDatasetWrapper mainDataset = datasetWrappers[0]; JFreeChart chart = ChartFactory.createTimeSeriesChart(mainDataset.getSeriesName(), "Time", mainDataset.getSeriesName(), mainDataset.getDataset(), true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); // all adjustments for first/main dataset plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum()); plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum()); // some additional "design" stuff for the plot plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor()); plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke())); for (int i = 1; i < datasetWrappers.length; i++) { XYDatasetWrapper wrapper = datasetWrappers[i]; plot.setDataset(i, wrapper.getDataset()); chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName()); NumberAxis axis = new NumberAxis(wrapper.getSeriesName()); plot.setRangeAxis(i, axis);//w w w. j av a2 s.c om plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT); plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0); plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0); // map the second dataset to the second axis plot.mapDatasetToRangeAxis(i, i); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke())); plot.setRenderer(i, renderer); plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor()); } // change the background and gridline colors plot.setBackgroundPaint(Color.white); plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); // format the date axis DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd.MM HH:mm")); axis.setTickUnit(new DateTickUnit(DateTickUnitType.HOUR, 1)); axis.setVerticalTickLabels(true); return chart; }
From source file:de.atomfrede.tools.evalutation.tools.plot.custom.CustomSimplePlot.java
@Override protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) { XYDatasetWrapper mainDataset = datasetWrappers[0]; JFreeChart chart = ChartFactory.createXYLineChart(mainDataset.getSeriesName(), "Index", mainDataset.getSeriesName(), mainDataset.getDataset(), PlotOrientation.VERTICAL, true, false, false);//from w w w . ja v a 2 s. c o m XYPlot plot = (XYPlot) chart.getPlot(); // all adjustments for first/main dataset plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum()); plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum()); // some additional "design" stuff for the plot plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor()); plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke())); for (int i = 1; i < datasetWrappers.length; i++) { XYDatasetWrapper wrapper = datasetWrappers[i]; plot.setDataset(i, wrapper.getDataset()); chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName()); NumberAxis axis = new NumberAxis(wrapper.getSeriesName()); plot.setRangeAxis(i, axis); plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT); plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0); plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0); // map the second dataset to the second axis plot.mapDatasetToRangeAxis(i, i); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke())); plot.setRenderer(i, renderer); plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor()); } // change the background and gridline colors plot.setBackgroundPaint(Color.white); plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); return chart; }
From source file:org.owasp.benchmark.score.report.Scatter.java
private JFreeChart display(String title, int height, int width, OverallResults or) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Note: this is a little weird, since each point is a separate series XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (OverallResult r : or.getResults()) { series.add(r.fpr * 100, r.tpr * 100); }//from ww w. ja va2 s . c o m dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Arial"; DecimalFormat pctFormat = new DecimalFormat("0'%'"); theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 16)); theme.setSmallFont(new Font(fontName, Font.PLAIN, 12)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); xyplot.setOutlineVisible(true); rangeAxis.setRange(-9.99, 109.99); rangeAxis.setNumberFormatOverride(pctFormat); rangeAxis.setTickLabelPaint(Color.decode("#666666")); rangeAxis.setMinorTickCount(5); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setAxisLineVisible(true); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setTickMarksVisible(true); rangeAxis.setLowerMargin(10); rangeAxis.setUpperMargin(10); xyplot.setRangeGridlineStroke(new BasicStroke()); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setRangeMinorGridlinesVisible(true); domainAxis.setRange(-5, 105); domainAxis.setNumberFormatOverride(pctFormat); domainAxis.setTickLabelPaint(Color.decode("#666666")); domainAxis.setMinorTickCount(5); domainAxis.setTickUnit(new NumberTickUnit(10)); domainAxis.setAxisLineVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setMinorTickMarksVisible(true); domainAxis.setLowerMargin(10); domainAxis.setUpperMargin(10); xyplot.setDomainGridlineStroke(new BasicStroke()); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setDomainMinorGridlinesVisible(true); chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.removeLegend(); chart.setPadding(new RectangleInsets(20, 20, 20, 20)); xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7")); // // setup item labels // XYItemRenderer renderer = xyplot.getRenderer(); // Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f); // for ( int i = 0; i < dataset.getSeriesCount(); i++ ) { // renderer.setSeriesShape(i, circle); // renderer.setSeriesPaint(i, Color.blue); // String letter = "" + ((String)dataset.getSeries(i).getKey()).charAt(0); // StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(letter); // renderer.setSeriesItemLabelGenerator(i, generator); // renderer.setSeriesItemLabelsVisible(i, true); // ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER ); // renderer.setSeriesPositiveItemLabelPosition(i, position); // } makeDataLabels(or, xyplot); makeLegend(or, 57, 48, dataset, xyplot); // put legend inside plot // LegendTitle lt = new LegendTitle(xyplot); // lt.setItemFont(theme.getSmallFont()); // lt.setPosition(RectangleEdge.RIGHT); // lt.setItemFont(theme.getSmallFont()); // XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT); // ta.setMaxWidth(0.48); // xyplot.addAnnotation(ta); // draw guessing line Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 }, 0); XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red); xyplot.addAnnotation(guessing); XYPointerAnnotation worse = makePointer(75, 0, "Worse than guessing", TextAnchor.TOP_CENTER, 90); xyplot.addAnnotation(worse); XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270); xyplot.addAnnotation(better); XYTextAnnotation time = new XYTextAnnotation("Tool run time: " + or.getTime(), 12, -5.6); time.setTextAnchor(TextAnchor.TOP_LEFT); time.setFont(theme.getRegularFont()); time.setPaint(Color.red); xyplot.addAnnotation(time); XYTextAnnotation stroketext = new XYTextAnnotation(" Random Guess", 88, 107); stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.red); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red); xyplot.setBackgroundPaint(Color.white); xyplot.addAnnotation(strokekey); ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:org.owasp.benchmark.score.report.ScatterScores.java
private JFreeChart display(String title, int height, int width, List<Report> toolResults) { JFrame f = new JFrame(title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("Scores"); for (int i = 0; i < toolResults.size(); i++) { Report toolReport = toolResults.get(i); OverallResults overallResults = toolReport.getOverallResults(); series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100); }//from w w w .ja v a 2 s. c om dataset.addSeries(series); chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset, PlotOrientation.VERTICAL, true, true, false); String fontName = "Arial"; DecimalFormat pctFormat = new DecimalFormat("0'%'"); theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title theme.setRegularFont(new Font(fontName, Font.PLAIN, 16)); theme.setSmallFont(new Font(fontName, Font.PLAIN, 12)); theme.setRangeGridlinePaint(Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setGridBandPaint(Color.red); theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint(Color.decode("#666666")); theme.apply(chart); XYPlot xyplot = chart.getXYPlot(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); xyplot.setOutlineVisible(true); rangeAxis.setRange(-5, 109.99); rangeAxis.setNumberFormatOverride(pctFormat); rangeAxis.setTickLabelPaint(Color.decode("#666666")); rangeAxis.setMinorTickCount(5); rangeAxis.setTickUnit(new NumberTickUnit(10)); rangeAxis.setAxisLineVisible(true); rangeAxis.setMinorTickMarksVisible(true); rangeAxis.setTickMarksVisible(true); rangeAxis.setLowerMargin(10); rangeAxis.setUpperMargin(10); xyplot.setRangeGridlineStroke(new BasicStroke()); xyplot.setRangeGridlinePaint(Color.lightGray); xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setRangeMinorGridlinesVisible(true); domainAxis.setRange(-5, 105); domainAxis.setNumberFormatOverride(pctFormat); domainAxis.setTickLabelPaint(Color.decode("#666666")); domainAxis.setMinorTickCount(5); domainAxis.setTickUnit(new NumberTickUnit(10)); domainAxis.setAxisLineVisible(true); domainAxis.setTickMarksVisible(true); domainAxis.setMinorTickMarksVisible(true); domainAxis.setLowerMargin(10); domainAxis.setUpperMargin(10); xyplot.setDomainGridlineStroke(new BasicStroke()); xyplot.setDomainGridlinePaint(Color.lightGray); xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD")); xyplot.setDomainMinorGridlinesVisible(true); chart.setTextAntiAlias(true); chart.setAntiAlias(true); chart.removeLegend(); chart.setPadding(new RectangleInsets(20, 20, 20, 20)); xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7")); // // setup item labels // XYItemRenderer renderer = xyplot.getRenderer(); // Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f); // for ( int i = 0; i < dataset.getSeriesCount(); i++ ) { // renderer.setSeriesShape(i, circle); // renderer.setSeriesPaint(i, Color.blue); // String label = ""+((String)dataset.getSeries(i).getKey()); // int idx = label.indexOf( ':'); // label = label.substring( 0, idx ); // StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label); // renderer.setSeriesItemLabelGenerator(i, generator); // renderer.setSeriesItemLabelsVisible(i, true); // ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER ); // renderer.setSeriesPositiveItemLabelPosition(i, position); // } makeDataLabels(toolResults, xyplot); makeLegend(toolResults, 57, 48, dataset, xyplot); Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 }, 0); for (XYDataItem item : (List<XYDataItem>) series.getItems()) { double x = item.getX().doubleValue(); double y = item.getY().doubleValue(); double z = (x + y) / 2; XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue); xyplot.addAnnotation(score); } // // put legend inside plot // LegendTitle lt = new LegendTitle(xyplot); // lt.setItemFont(theme.getSmallFont()); // lt.setPosition(RectangleEdge.RIGHT); // lt.setItemFont(theme.getSmallFont()); // XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT); // ta.setMaxWidth(0.48); // xyplot.addAnnotation(ta); // draw guessing line XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red); xyplot.addAnnotation(guessing); XYPointerAnnotation worse = makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90); xyplot.addAnnotation(worse); XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270); xyplot.addAnnotation(better); XYTextAnnotation stroketext = new XYTextAnnotation(" Random Guess", 88, 107); stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT); stroketext.setBackgroundPaint(Color.white); stroketext.setPaint(Color.red); stroketext.setFont(theme.getRegularFont()); xyplot.addAnnotation(stroketext); XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red); xyplot.setBackgroundPaint(Color.white); xyplot.addAnnotation(strokekey); ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false, false, false); f.add(cp); f.pack(); f.setLocationRelativeTo(null); // f.setVisible(true); return chart; }
From source file:org.cds06.speleograph.graph.GraphEditor.java
/** * Creates a modal dialog by specifying the attached {@link GraphPanel}. * <p>Please look at {@link javax.swing.JDialog#JDialog()} to see defaults params applied to this Dialog.</p> *///from w w w.ja v a 2s .c o m public GraphEditor(GraphPanel panel) { super((Frame) SwingUtilities.windowForComponent(panel), true); Validate.notNull(panel); this.graphPanel = panel; KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); mainPanel.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); setContentPane(mainPanel); mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); this.setTitle(I18nSupport.translate("menus.graph.graphEditor")); { // This section use FormLayout which is an external layout for Java, consult the doc before edit the // following lines ! final FormLayout layout = new FormLayout( "right:max(40dlu;p), 4dlu, p:grow, 4dlu, p, 4dlu, p:grow, 4dlu, p", //NON-NLS "p,4dlu,p,4dlu,p,4dlu,p,4dlu,p" //NON-NLS ); PanelBuilder builder = new PanelBuilder(layout); final JLabel colorLabel = new JLabel(); final JTextField titleForGraph = new JTextField( graphPanel.getChart().getTitle() != null ? graphPanel.getChart().getTitle().getText() : ""); final JLabel colorXYPlotLabel = new JLabel(); final JLabel colorGridLabel = new JLabel(); final JCheckBox showLegendCheckBox = new JCheckBox("Afficher la lgende", graphPanel.getChart().getLegend().isVisible()); { builder.addLabel("Titre :", "1,1"); builder.add(titleForGraph, "3,1,7,1"); } { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.backgroundColor"), "1,3"); colorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorLabel.setText(" "); colorLabel.setBackground((Color) graphPanel.getChart().getBackgroundPaint()); colorLabel.setOpaque(true); colorLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorLabel.getBackground()); if (c != null) { colorLabel.setBackground(c); } } }); builder.add(colorLabel, "3,3,5,1"); builder.add(edit, "9,3"); } final XYPlot xyPlot = graphPanel.getChart().getXYPlot(); { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.graphColor"), "1,5"); colorXYPlotLabel.setText(" "); colorXYPlotLabel.setOpaque(true); colorXYPlotLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorXYPlotLabel.setBackground((Color) xyPlot.getBackgroundPaint()); colorXYPlotLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorXYPlotLabel.getBackground()); if (c != null) { colorXYPlotLabel.setBackground(c); } } }); builder.add(colorXYPlotLabel, "3,5,5,1"); builder.add(edit, "9,5"); } { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.gridColor"), "1,7"); colorGridLabel.setOpaque(true); colorGridLabel.setText(" "); colorGridLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorGridLabel.setBackground((Color) xyPlot.getRangeGridlinePaint()); colorGridLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorGridLabel.getBackground()); if (c != null) { colorGridLabel.setBackground(c); } } }); builder.add(colorGridLabel, "3,7,5,1"); builder.add(edit, "9,7"); } { builder.add(showLegendCheckBox, "1,9,9,1"); } mainPanel.add(builder.build(), BorderLayout.CENTER); ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(); buttonBarBuilder.addGlue(); buttonBarBuilder.addButton(new AbstractAction() { { putValue(NAME, I18nSupport.translate("cancel")); } @Override public void actionPerformed(ActionEvent e) { GraphEditor.this.setVisible(false); } }); buttonBarBuilder.addButton(new AbstractAction() { { putValue(NAME, I18nSupport.translate("ok")); } @Override public void actionPerformed(ActionEvent e) { if (titleForGraph.getText().isEmpty()) graphPanel.getChart().setTitle((String) null); else graphPanel.getChart().setTitle(titleForGraph.getText()); { Color c = colorGridLabel.getBackground(); xyPlot.setRangeGridlinePaint(c); xyPlot.setRangeMinorGridlinePaint(c); xyPlot.setDomainGridlinePaint(c); xyPlot.setDomainMinorGridlinePaint(c); } graphPanel.getChart().setBackgroundPaint(colorLabel.getBackground()); xyPlot.setBackgroundPaint(colorXYPlotLabel.getBackground()); graphPanel.getChart().getLegend().setVisible(showLegendCheckBox.isSelected()); GraphEditor.this.setVisible(false); } }); mainPanel.add(buttonBarBuilder.build(), BorderLayout.SOUTH); } pack(); Dimension d = this.getPreferredSize(); this.setSize(new Dimension(d.width + 20, d.height)); setResizable(false); }