List of usage examples for org.jfree.chart.plot XYPlot getRenderer
public XYItemRenderer getRenderer()
From source file:it.eng.spagobi.engines.chart.bo.charttypes.scattercharts.MarkerScatter.java
public JFreeChart createChart(DatasetMap datasets) { DefaultXYDataset dataset = (DefaultXYDataset) datasets.getDatasets().get("1"); JFreeChart chart = ChartFactory.createScatterPlot(name, yLabel, xLabel, dataset, PlotOrientation.HORIZONTAL, false, true, false);//w ww .j av a 2s. co m TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); chart.setBackgroundPaint(Color.white); if (subName != null && !subName.equals("")) { TextTitle subTitle = setStyleTitle(subName, styleSubTitle); chart.addSubtitle(subTitle); } XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); //defines colors int seriesN = dataset.getSeriesCount(); if ((colorMap != null && colorMap.size() > 0) || (defaultColor != null && !defaultColor.equals(""))) { for (int i = 0; i < seriesN; i++) { String serieName = (String) dataset.getSeriesKey(i); Color color = new Color(Integer.decode(defaultColor).intValue()); if (colorMap != null && colorMap.size() > 0) color = (Color) colorMap.get(serieName); if (color != null) renderer.setSeriesPaint(i, color); } } // add un interval marker for the Y axis... if (yMarkerStartInt != null && yMarkerEndInt != null && !yMarkerStartInt.equals("") && !yMarkerEndInt.equals("")) { Marker intMarkerY = new IntervalMarker(Double.parseDouble(yMarkerStartInt), Double.parseDouble(yMarkerEndInt)); intMarkerY.setLabelOffsetType(LengthAdjustmentType.EXPAND); intMarkerY.setPaint( new Color(Integer.decode((yMarkerIntColor.equals("")) ? "0" : yMarkerIntColor).intValue())); //intMarkerY.setLabel(yMarkerLabel); intMarkerY.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); intMarkerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(intMarkerY, Layer.BACKGROUND); } // add un interval marker for the X axis... if (xMarkerStartInt != null && xMarkerEndInt != null && !xMarkerStartInt.equals("") && !xMarkerEndInt.equals("")) { Marker intMarkerX = new IntervalMarker(Double.parseDouble(xMarkerStartInt), Double.parseDouble(xMarkerEndInt)); intMarkerX.setLabelOffsetType(LengthAdjustmentType.EXPAND); intMarkerX.setPaint( new Color(Integer.decode((xMarkerIntColor.equals("")) ? "0" : xMarkerIntColor).intValue())); //intMarkerX.setLabel(xMarkerLabel); intMarkerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); intMarkerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(intMarkerX, Layer.BACKGROUND); } // add a labelled marker for the Y axis... if (yMarkerValue != null && !yMarkerValue.equals("")) { Marker markerY = new ValueMarker(Double.parseDouble(yMarkerValue)); markerY.setLabelOffsetType(LengthAdjustmentType.EXPAND); if (!yMarkerColor.equals("")) markerY.setPaint(new Color(Integer.decode(yMarkerColor).intValue())); markerY.setLabel(yMarkerLabel); markerY.setLabelFont(new Font("Arial", Font.BOLD, 11)); markerY.setLabelAnchor(RectangleAnchor.TOP_RIGHT); markerY.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(markerY, Layer.BACKGROUND); } // add a labelled marker for the X axis... if (xMarkerValue != null && !xMarkerValue.equals("")) { Marker markerX = new ValueMarker(Double.parseDouble(xMarkerValue)); markerX.setLabelOffsetType(LengthAdjustmentType.EXPAND); if (!xMarkerColor.equals("")) markerX.setPaint(new Color(Integer.decode(xMarkerColor).intValue())); markerX.setLabel(xMarkerLabel); markerX.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); markerX.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addRangeMarker(markerX, Layer.BACKGROUND); } if (xRangeLow != null && !xRangeLow.equals("") && xRangeHigh != null && !xRangeHigh.equals("")) { if (Double.valueOf(xRangeLow).doubleValue() > xMin) xRangeLow = String.valueOf(xMin); if (Double.valueOf(xRangeHigh).doubleValue() < xMax) xRangeHigh = String.valueOf(xMax); ValueAxis rangeAxis = plot.getRangeAxis(); //rangeAxis.setRange(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh)); rangeAxis.setRangeWithMargins(Double.parseDouble(xRangeLow), Double.parseDouble(xRangeHigh)); } else { NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); rangeAxis.setRange(xMin, xMax); } if (yRangeLow != null && !yRangeLow.equals("") && yRangeHigh != null && !yRangeHigh.equals("")) { if (Double.valueOf(yRangeLow).doubleValue() > yMin) yRangeLow = String.valueOf(yMin); if (Double.valueOf(yRangeHigh).doubleValue() < yMax) yRangeHigh = String.valueOf(yMax); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); //domainAxis.setRange(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh)); domainAxis.setRangeWithMargins(Double.parseDouble(yRangeLow), Double.parseDouble(yRangeHigh)); domainAxis.setAutoRangeIncludesZero(false); } else { NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRange(true); domainAxis.setRange(yMin, yMax); domainAxis.setAutoRangeIncludesZero(false); } //add annotations if requested if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("true")) { if (annotationMap == null || annotationMap.size() == 0) logger.error("Annotations on the chart are requested but the annotationMap is null!"); else { int cont = 1; for (Iterator iterator = annotationMap.keySet().iterator(); iterator.hasNext();) { String text = (String) iterator.next(); String pos = (String) annotationMap.get(text); double x = Double.parseDouble(pos.substring(0, pos.indexOf("__"))); double y = Double.parseDouble(pos.substring(pos.indexOf("__") + 2)); //default up position XYTextAnnotation annotation = new XYTextAnnotation(text, y - 1, x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1)); if (cont % 2 != 0) //dx annotation = new XYTextAnnotation(text, y, x + ((text.length() > 20) ? text.length() / 3 + 1 : text.length() / 2 + 1)); else //sx //annotation = new XYTextAnnotation(text, y, x-((text.length()%2==0)?text.length():text.length()-1)); annotation = new XYTextAnnotation(text, y, x - (text.length() - 1)); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); //annotation.setRotationAngle(Math.PI / 4.0); annotation.setRotationAngle(0.0); // horizontal plot.addAnnotation(annotation); cont++; } renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8)); } } else if (viewAnnotations != null && viewAnnotations.equalsIgnoreCase("false")) { renderer.setShape(new Ellipse2D.Double(-3, -5, 8, 8)); } if (legend == true) { drawLegend(chart); } return chart; }
From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java
public ChartPanel interpolado(int index) { // create the chart... JFreeChart graf = ChartFactory.createXYLineChart("Interpolado", // chart title "Recall", // x axis label "Precision", // y axis label createDatasetInterpoled(index), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*ww w . j av a 2 s.c o m*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... graf.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) graf.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(false); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); plot.setRenderer(1, renderer2); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. ChartPanel myChartPanel = new ChartPanel(graf, true); return myChartPanel; }
From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java
public ChartPanel media11() { // create the chart... JFreeChart graf = ChartFactory.createXYLineChart("Media 11 Pontos", // chart title "Recall", // x axis label "Precision", // y axis label createDatasetOnze(), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*from w w w. j a v a 2s .c o m*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... graf.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) graf.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(false); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); plot.setRenderer(1, renderer2); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. ChartPanel myChartPanel = new ChartPanel(graf, true); return myChartPanel; }
From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java
public ChartPanel media11(int index) { // create the chart... JFreeChart graf = ChartFactory.createXYLineChart("Media 11 pontos", // chart title "Recall", // x axis label "Precision", // y axis label createDatasetOnze(index), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );// w w w .j a v a2s .c om // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... graf.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) graf.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(false); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); plot.setRenderer(1, renderer2); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. ChartPanel myChartPanel = new ChartPanel(graf, true); return myChartPanel; }
From source file:br.usp.icmc.gazetteer.SemanticSearchTest.Grafico.java
/***************************************** INDIVIDUAIS **************************************************/ public ChartPanel precisionrecall(int index) { // create the chart... JFreeChart graf = ChartFactory.createXYLineChart("Precision Recall", // chart title "Recall", // x axis label "Precision", // y axis label createDatasetprecision(index), // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );/*from ww w . ja v a 2 s .c om*/ // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... graf.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) graf.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setShapesVisible(false); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); plot.setRenderer(1, renderer2); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. ChartPanel myChartPanel = new ChartPanel(graf, true); return myChartPanel; }
From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYPrincipalComponentAnalysisPlot.java
private void createChart() { String xLabel = component1.toString(); String yLabel = component2.toString(); pcaChart = ChartFactory.createScatterPlot("Principal Component Analysis", xLabel, yLabel, null, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) pcaChart.getPlot(); buildLegend();/*from w w w . j a v a2 s .c o m*/ plot.setNoDataMessage(null); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setToolTipGenerator(new StandardXYToolTipGenerator()); renderer.setUseOutlinePaint(true); plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairVisible(false); // XYShapeAnnotation annotation = new XYShapeAnnotation(new Rectangle2D.Double(25.0, 25.0, 5, 5)); // // plot.addAnnotation(annotation); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); //should determine axis range using datapoints. DataRange component1Range = getDataRange(dataPoints, PCAcomponent.PC1); DataRange component2Range = getDataRange(dataPoints, PCAcomponent.PC2); DataRange component3Range = getDataRange(dataPoints, PCAcomponent.PC3); Double pc1AbsMax = Math.max(Math.abs(component1Range.getMaxRange()), Math.abs(component1Range.getMinRange())); Double pc2AbsMax = Math.max(Math.abs(component2Range.getMaxRange()), Math.abs(component2Range.getMinRange())); Double pc3AbsMax = Math.max(Math.abs(component3Range.getMaxRange()), Math.abs(component3Range.getMinRange())); Double maxAbsVal = Math.max(pc1AbsMax, pc2AbsMax); maxAbsVal = Math.max(maxAbsVal, pc3AbsMax); //maxAbsVal = Math.max(100.0, maxAbsVal); domainAxis.setAutoRangeIncludesZero(false); double tickUnit = 25.0; if (maxAbsVal <= 25.0) { tickUnit = 5.0; } else if (maxAbsVal <= 50.0) { tickUnit = 10.0; } domainAxis.setTickUnit(new NumberTickUnit(tickUnit)); rangeAxis.setTickUnit(new NumberTickUnit(tickUnit)); double glyphScaleFactor = (maxAbsVal * 2.0) / 600.0; //assuming 600 pixels for the graph double adjAbsVal = Math.ceil(maxAbsVal + (glyphScaleFactor * 8.0)); //domainAxis.setRange(-maxAbsVal, maxAbsVal); domainAxis.setRange(-adjAbsVal, adjAbsVal); //rangeAxis.setRange(-maxAbsVal, maxAbsVal); rangeAxis.setRange(-adjAbsVal, adjAbsVal); createGlyphsAndAddToPlot(plot, glyphScaleFactor); // Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green); //try and match the UI e9e9e9 Paint p = new Color(233, 233, 233); pcaChart.setBackgroundPaint(p); }
From source file:com.intel.stl.ui.common.view.ComponentFactory.java
public static JFreeChart createXYBarChart(String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset, XYItemLabelGenerator labelGenerator) { if (dataset == null) { throw new IllegalArgumentException("No dataset."); }/*from ww w . j av a 2 s. c o m*/ JFreeChart jfreechart = ChartFactory.createXYBarChart(null, xAxisLabel, false, yAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); xyplot.setBackgroundPaint(null); xyplot.setOutlinePaint(null); xyplot.setRangeGridlinePaint(UIConstants.INTEL_DARK_GRAY); NumberAxis axis = (NumberAxis) xyplot.getRangeAxis(); axis.setRangeType(RangeType.POSITIVE); axis.setLabelFont(UIConstants.H5_FONT); xyplot.getDomainAxis().setLabelFont(UIConstants.H5_FONT); XYBarRenderer renderer = (XYBarRenderer) xyplot.getRenderer(); renderer.setShadowVisible(false); renderer.setBaseItemLabelsVisible(true); if (labelGenerator != null) { renderer.setBaseItemLabelGenerator(labelGenerator); } renderer.setBaseItemLabelFont(UIConstants.H5_FONT); renderer.setBarPainter(new StandardXYBarPainter()); renderer.setSeriesPaint(0, UIConstants.INTEL_BLUE); return jfreechart; }
From source file:domain.Grafica.java
public JFreeChart createChart(XYDataset dataset) { /*/* w w w .ja v a 2 s. c o m*/ ///* NumberAxis numberaxis = new NumberAxis(""); numberaxis.setAutoRangeIncludesZero(false); DateAxis dateaxis = new DateAxis(""); NumberAxis numberaxis1 = new NumberAxis(""); numberaxis1.setAutoRangeIncludesZero(false); XYSplineRenderer xysplinerenderer = new XYSplineRenderer(); XYPlot xyplot = new XYPlot(dataset, dateaxis, numberaxis1, xysplinerenderer); // xyplot.setBackgroundPaint(new Color(238, 242, 250));// // xyplot.setDomainGridlinePaint(new Color(255, 255, 255)); // xyplot.setRangeGridlinePaint(new Color(238, 242, 250)); xyplot.getRenderer().setSeriesPaint(0, Color.RED); xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); renderer.setSeriesShapesVisible(0, true);//FIXME Dots // xyplot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits()); JFreeChart jfreechart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, xyplot, false); jfreechart.setBackgroundPaint(Color.white); DateAxis axis = (DateAxis) xyplot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss aa")); xyplot.getRangeAxis().setUpperBound(maxPeso * 1.25); xyplot.getRangeAxis().setLowerBound(minPeso * 0.75); cargarImagen(); // xyplot.setBackgroundImage(i); //jfreechart.setBackgroundImage(i); return jfreechart; */ JFreeChart chart = ChartFactory.createTimeSeriesChart("", // title "Fecha/Hora", // x-axis label "Pesos(Kg.)", // y-axis label dataset, // data false, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.GRAY); plot.setRangeGridlinePaint(Color.GRAY); /* plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); */ plot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D)); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); } NumberAxis range = (NumberAxis) plot.getRangeAxis(); // range.setAutoRangeIncludesZero(true); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss")); plot.getRangeAxis().setUpperBound(maxPeso * 1.25); plot.getRangeAxis().setLowerBound(minPeso * 0.75); return chart; }
From source file:edu.ucla.stat.SOCR.chart.SuperDotChart.java
/** * Creates a chart.// w ww . jav a 2s . co m * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart1(XYDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title domainLabel, // x axis label rangeLabel, // y axis label dataset, // data PlotOrientation.HORIZONTAL, !legendPanelOn, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); // change the auto tick unit selection to integer units only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:edu.ucla.stat.SOCR.chart.SuperXYZChart.java
/** * Creates a chart.//from w ww .ja v a 2s.c o m * * @param dataset the dataset. * * @return a chart. */ protected JFreeChart createChart(XYZDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBubbleChart(chartTitle, // chart titl rangeLabel, // y axis label domainLabel, // x axis label dataset, // data PlotOrientation.VERTICAL, !legendPanelOn, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.65f); XYItemRenderer renderer = plot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); // increase the margins to account for the fact that the auto-range // doesn't take into account the bubble size... NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setLowerMargin(0.15); domainAxis.setUpperMargin(0.15); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); return chart; }