List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer setBaseLinesVisible
public void setBaseLinesVisible(boolean flag)
From source file:edu.ucla.stat.SOCR.applications.demo.BlackScholesApplication.java
void updateGraph() { //System.out.println("UpdateGraph get called") calculate();/*w w w . j av a2s .c o m*/ XYSeriesCollection ds = createDataset(); JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xAxis, // x axis label yAxis, // y axis label ds, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); XYPlot subplot1 = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) subplot1.getRenderer(); renderer1.setSeriesPaint(0, Color.red); renderer1.setSeriesPaint(1, Color.blue); Shape shape = renderer1.getBaseShape(); renderer1.setSeriesShape(2, shape); renderer1.setSeriesShape(3, shape); renderer1.setBaseLinesVisible(true); renderer1.setBaseShapesVisible(true); renderer1.setBaseShapesFilled(true); renderer1.setSeriesShapesVisible(0, false); NumberAxis rangeAxis = (NumberAxis) subplot1.getRangeAxis(); rangeAxis.setAutoRangeIncludesZero(false); chartPanel = new ChartPanel(chart, false); chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y)); upContainer = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftPanel), new JScrollPane(chartPanel)); this.getMainPanel().removeAll(); this.getMainPanel().add(new JScrollPane(upContainer), BorderLayout.CENTER); this.getMainPanel().validate(); // getRecordTable().setText("Any Explaination goes here."); // }
From source file:edu.ucla.stat.SOCR.applications.demo.StockSimulationApplication.java
void updateGraph() { //System.out.println("UpdateGraph get called") calculate();//from w w w. j a v a 2s. c o m XYSeriesCollection ds = createDataset(); JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xAxis, // x axis label yAxis, // y axis label ds, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); XYPlot subplot1 = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) subplot1.getRenderer(); renderer1.setSeriesPaint(0, Color.red); renderer1.setSeriesPaint(1, Color.blue); renderer1.setSeriesPaint(2, Color.green); renderer1.setSeriesPaint(3, Color.gray); /* Shape shape = renderer1.getBaseShape(); renderer1.setSeriesShape(2, shape); renderer1.setSeriesShape(3, shape);*/ renderer1.setBaseLinesVisible(true); renderer1.setBaseShapesVisible(true); renderer1.setBaseShapesFilled(true); chartPanel = new ChartPanel(chart, false); chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y)); upContainer = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftPanel), new JScrollPane(chartPanel)); this.getMainPanel().removeAll(); this.getMainPanel().add(new JScrollPane(upContainer), BorderLayout.CENTER); this.getMainPanel().validate(); // getRecordTable().setText("Any Explaination goes here."); // }
From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java
private JFreeChart createLineChart(String title, String xLabel, String yLabel, XYDataset dataset, String other) {/* w w w .jav a 2 s . co m*/ // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); chart.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainGridlinePaint(Color.lightGray); //plot.setNoDataMessage("No data available"); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.02); rangeAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLowerMargin(0.02); // customise the renderer... XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseLinesVisible(true); renderer.setDrawOutlines(true); renderer.setBaseShapesFilled(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); if (other.toLowerCase().indexOf("noline") != -1) { renderer.setBaseShapesVisible(true); renderer.setBaseLinesVisible(false); } if (other.toLowerCase().indexOf("noshape") != -1) { renderer.setBaseShapesVisible(false); renderer.setBaseLinesVisible(true); } if (other.toLowerCase().indexOf("excludeszero") != -1) { rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setAutoRangeIncludesZero(false); } return chart; }
From source file:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java
public void setChartType(int type) { if (type == SCATTER_PLOT) { isSymbolVisible = true;// w w w . j a v a 2 s .co m isLineVisible = false; } else { isSymbolVisible = false; isLineVisible = true; } XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chartPanel.getChart().getXYPlot().getRenderer(); renderer.setBaseLinesVisible(isLineVisible); renderer.setBaseShapesVisible(isSymbolVisible); }
From source file:edu.ucla.stat.SOCR.analyses.gui.Chart.java
private JFreeChart createLineChart(String title, String xLabel, String yLabel, XYDataset dataset, Color[] colors, String other) { // create the chart... JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title xLabel, // domain axis label yLabel, // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls );/*w w w . j a va2s . c o m*/ XYPlot plot = chart.getXYPlot(); chart.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setDomainGridlinePaint(Color.lightGray); //plot.setNoDataMessage("No data available"); // customise the range axis... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setUpperMargin(0.02); rangeAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLowerMargin(0.02); // customise the renderer... XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseLinesVisible(true); renderer.setDrawOutlines(true); renderer.setBaseShapesFilled(true); renderer.setUseFillPaint(true); renderer.setBaseFillPaint(Color.white); for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, colors[i]); } if (other.toLowerCase().indexOf("noline") != -1) { renderer.setBaseShapesVisible(true); renderer.setBaseLinesVisible(false); } if (other.toLowerCase().indexOf("noshape") != -1) { renderer.setBaseShapesVisible(false); renderer.setBaseLinesVisible(true); } if (other.toLowerCase().indexOf("excludeszero") != -1) { rangeAxis.setAutoRangeIncludesZero(false); domainAxis.setAutoRangeIncludesZero(false); } if (other.toLowerCase().indexOf("color") != -1) { renderer.setBaseShapesVisible(false); renderer.setBaseLinesVisible(true); } return chart; }
From source file:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java
private ChartPanel createChartPanel() { JFreeChart xyChart = ChartFactory.createXYLineChart("f", "x", "y", plotSeries, PlotOrientation.VERTICAL, false, true, false);/* w w w. ja va 2 s . c o m*/ RenderingHints hints = xyChart.getRenderingHints(); hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); xyChart.setBackgroundPaint(Color.WHITE); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyChart.getXYPlot().getRenderer(); renderer.setBaseLinesVisible(isLineVisible); renderer.setBaseShapesVisible(isSymbolVisible); LegendTitle legend = new LegendTitle(renderer); legend.setPosition(RectangleEdge.BOTTOM); xyChart.addLegend(legend); xyChart.getXYPlot().getRangeAxis().setStandardTickUnits(createTickUnits()); //xyChart.getXYPlot().getRangeAxis().setStandardTickUnits(new StandardTickUnitSource()); xyChart.getXYPlot().getRangeAxis().setAutoRangeMinimumSize(1.0e-45); chartPanel = new ChartPanel(xyChart); JPopupMenu popup = chartPanel.getPopupMenu(); popup.remove(1); // removes separator popup.remove(1); // removes save as... popup.add(createLinePropMenu()); popup.add(createAxesPropMenu()); popup.addSeparator(); popup.add(createExportMenu()); return chartPanel; }
From source file:com.AandR.beans.plotting.LinePlotPanel.LinePlotPanel.java
public void setChartType(XYDataset dataset, int type) { if (type == SCATTER_PLOT) { isSymbolVisible = true;/*w ww .j a v a2 s . c o m*/ isLineVisible = false; } else { isSymbolVisible = false; isLineVisible = true; } XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chartPanel.getChart().getXYPlot() .getRendererForDataset(dataset); renderer.setBaseLinesVisible(isLineVisible); renderer.setBaseShapesVisible(isSymbolVisible); }
From source file:my.electrochem.ElectrochemUI.java
private ChartPanel createChartPanel() { //creates a line chart object //returns the chart panel String chartTitle = "i-E curve"; String xAxisLabel = "E (V)"; String yAxisLabel = "i (A)"; dataset1 = createEmptyDataset();/*from w ww.j a v a2 s . c om*/ JFreeChart chart = ChartFactory.createScatterPlot(chartTitle, xAxisLabel, yAxisLabel, dataset1); XYPlot plot = chart.getXYPlot(); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.setDomainCrosshairLockedOnData(false); plot.setRangeCrosshairLockedOnData(false); /*chart.addProgressListener(new ChartProgressListener() { @Override public void chartProgress(ChartProgressEvent cpe) { if (cpe.getType() == ChartProgressEvent.DRAWING_FINISHED) { //System.out.println("Click event!!"); XYPlot xyPlot2 = cpe.getChart().getXYPlot(); System.out.println("drawing finished"); System.out.println("Xreal:"+xyPlot2.getDomainCrosshairValue() +"Yreal:"+xyPlot2.getRangeCrosshairValue()); if (click) { System.out.println("click true"); if (x1 == -423.0) { x1 = 0.0; y1 = 0.0; } if (x1 == 0.0 && y1 == 0.0) { System.out.println("print 0,0"); click = true; x1 = xyPlot2.getDomainCrosshairValue(); y1 = xyPlot2.getRangeCrosshairValue(); //xyPlot2.clearAnnotations(); } else { xyPlot2.clearAnnotations(); System.out.println("true-false"); click = false; x1 = xyPlot2.getDomainCrosshairValue(); y1 = xyPlot2.getRangeCrosshairValue(); } } else { System.out.println("click false"); x2 = xyPlot2.getDomainCrosshairValue(); y2 = xyPlot2.getRangeCrosshairValue(); createLineAnn(xyPlot2, x1, y1, x2, y2); click = true; } } } });*/ XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); // sets paint color for each series //renderer.setSeriesPaint(0, Color.RED); // sets thickness for series (using strokes) //renderer.setSeriesStroke(0, new BasicStroke(5.0f)); renderer.setBaseLinesVisible(true); //renderer.setSeriesLinesVisible(0, true); //renderer.setBaseShapesFilled(true); renderer.setBaseShapesVisible(false); //srenderer.setDrawSeriesLineAsPath(false); plot.setOutlinePaint(Color.BLUE); plot.setOutlineStroke(new BasicStroke(2.0f)); plot.setBackgroundPaint(Color.DARK_GRAY); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.BLACK); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.BLACK); plot.setRenderer(renderer); return new ChartPanel(chart); }
From source file:weka.gui.beans.JFreeChartOffscreenChartRenderer.java
/** * Render an XY scatter plot//from w ww. j a v a 2 s . co m * * @param width the width of the resulting chart in pixels * @param height the height of the resulting chart in pixels * @param series a list of Instances - one for each series to be plotted * @param xAxis the name of the attribute for the x-axis (all series Instances * are expected to have an attribute of the same type with this name) * @param yAxis the name of the attribute for the y-axis (all series Instances * are expected to have an attribute of the same type with this name) * @param optionalArgs optional arguments to the renderer (may be null) * * @return a BufferedImage containing the chart * @throws Exception if there is a problem rendering the chart */ public BufferedImage renderXYScatterPlot(int width, int height, List<Instances> series, String xAxis, String yAxis, List<String> optionalArgs) throws Exception { String plotTitle = "Scatter Plot"; String userTitle = getOption(optionalArgs, "-title"); plotTitle = (userTitle != null) ? userTitle : plotTitle; String colorAtt = getOption(optionalArgs, "-color"); if (series.size() == 1 && colorAtt != null && colorAtt.length() > 0) { int colIndex = getIndexOfAttribute(series.get(0), colorAtt); if (colIndex >= 0 && series.get(0).attribute(colIndex).isNominal()) { // split single series out into multiple instances objects - one // per class series = splitToClasses(series.get(0), colIndex); for (Instances insts : series) { insts.setClassIndex(colIndex); } } } Instances masterInstances = series.get(0); int xAx = getIndexOfAttribute(masterInstances, xAxis); int yAx = getIndexOfAttribute(masterInstances, yAxis); if (xAx < 0) { xAx = 0; } if (yAx < 0) { yAx = 0; } // Set the axis names just in case we've been supplied with // /first, /last or /<num> xAxis = masterInstances.attribute(xAx).name(); yAxis = masterInstances.attribute(yAx).name(); // look for an additional attribute that stores the // shape sizes - could be either nominal or numeric errors. // We only use numeric error information String shapeSize = getOption(optionalArgs, "-shapeSize"); boolean nominalClass = (masterInstances.classIndex() >= 0 && masterInstances.classAttribute().isNominal()); int shapeSizeI = -1; if (shapeSize != null && shapeSize.length() > 0) { shapeSizeI = getIndexOfAttribute(masterInstances, shapeSize); } AbstractIntervalXYDataset xyDataset = null; if (shapeSizeI < 0 || nominalClass) { xyDataset = new XYSeriesCollection(); } else { xyDataset = new XYIntervalSeriesCollection(); } // add master series Series master = null; if (shapeSizeI < 0 || nominalClass) { master = new XYSeries(masterInstances.relationName()); } else { master = new XYIntervalSeries(masterInstances.relationName()); } AttributeStats xStats = masterInstances.attributeStats(xAx); AttributeStats yStats = masterInstances.attributeStats(yAx); double sizeRange = 0; double sizeMin = 0; if (shapeSizeI >= 0 && !nominalClass) { AttributeStats sStats = masterInstances.attributeStats(shapeSizeI); sizeRange = sStats.numericStats.max - sStats.numericStats.min; sizeMin = sStats.numericStats.min; } double xRange = 0; if (masterInstances.attribute(xAx).isNominal()) { xRange = masterInstances.attribute(xAx).numValues(); } else { xRange = xStats.numericStats.max - xStats.numericStats.min; } double yRange = 0; if (masterInstances.attribute(yAx).isNominal()) { xRange = masterInstances.attribute(yAx).numValues(); } else { yRange = yStats.numericStats.max - yStats.numericStats.min; } for (int i = 0; i < masterInstances.numInstances(); i++) { Instance inst = masterInstances.instance(i); if (!inst.isMissing(xAx) && !inst.isMissing(yAx)) { if (shapeSizeI < 0 || nominalClass) { ((XYSeries) master).add(inst.value(xAx), inst.value(yAx)); } else { double xBar = (inst.value(shapeSizeI) - sizeMin) / sizeRange; xBar *= (xRange / 5.0); // max of 1/5th the x range double yBar = (inst.value(shapeSizeI) - sizeMin) / sizeRange; yBar *= (yRange / 5.0); double x = inst.value(xAx); double y = inst.value(yAx); ((XYIntervalSeries) master).add(x, x - (xBar / 2.0), x + (xBar / 2.0), y, y - (yBar / 2.0), y + (yBar / 2.0)); } } } if (shapeSizeI < 0 || nominalClass) { ((XYSeriesCollection) xyDataset).addSeries((XYSeries) master); } else { ((XYIntervalSeriesCollection) xyDataset).addSeries((XYIntervalSeries) master); } // remaining series for (int i = 1; i < series.size(); i++) { Instances aSeriesI = series.get(i); Series aSeriesJ = null; if (shapeSizeI < 0 || nominalClass) { aSeriesJ = new XYSeries(aSeriesI.relationName()); } else { aSeriesJ = new XYIntervalSeries(aSeriesI.relationName()); } for (int j = 0; j < aSeriesI.numInstances(); j++) { Instance inst = aSeriesI.instance(j); if (!inst.isMissing(xAx) && !inst.isMissing(yAx)) { if (shapeSizeI < 0 || nominalClass) { ((XYSeries) aSeriesJ).add(inst.value(xAx), inst.value(yAx)); } else { double xBar = (inst.value(shapeSizeI) - sizeMin) / sizeRange; xBar *= (xRange / 5.0); // max of 1/10th the x range double yBar = (inst.value(shapeSizeI) - sizeMin) / sizeRange; yBar *= (yRange / 5.0); double x = inst.value(xAx); double y = inst.value(yAx); ((XYIntervalSeries) aSeriesJ).add(x, x - (xBar / 2.0), x + (xBar / 2.0), y, y - (yBar / 2.0), y + (yBar / 2.0)); } } } if (shapeSizeI < 0 || nominalClass) { ((XYSeriesCollection) xyDataset).addSeries((XYSeries) aSeriesJ); } else { ((XYIntervalSeriesCollection) xyDataset).addSeries((XYIntervalSeries) aSeriesJ); } } JFreeChart chart = ChartFactory.createXYLineChart(plotTitle, xAxis, yAxis, xyDataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(java.awt.Color.white); XYPlot plot = (XYPlot) chart.getPlot(); if (shapeSizeI < 0 || nominalClass) { XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true); renderer.setBaseShapesFilled(false); plot.setRenderer(renderer); } else { XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setDrawXError(true); renderer.setDrawYError(true); renderer.setBaseLinesVisible(false); plot.setRenderer(renderer); } BufferedImage image = chart.createBufferedImage(width, height); return image; }
From source file:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication.java
void updateGraph() { //System.out.println("UpdateGraph get called"); setupStockOptions();/*from w ww. ja va2 s .com*/ computeDataPoints(); e_serie = new XYSeries("equal", false); b_serie = new XYSeries("bigger", false); s_serie = new XYSeries("smaller", false); m_serie = new XYSeries("mouse", false); StringBuffer text = new StringBuffer(); text.append("mouse clicked at " + tooltip + "\n"); text.append("The stock combinations are:"); Iterator i = dataPoints.iterator(); while (i.hasNext()) { DataPoint dp = (DataPoint) i.next(); if (dp == minPoint) { e_serie.add(dp.std, dp.mean); } else if (dp.mean < minPoint.mean) s_serie.add(dp.std, dp.mean); else b_serie.add(dp.std, dp.mean); if (mouseClicked) { if (Double.parseDouble(tooltip_formatter.format(dp.std)) == Double .parseDouble(tooltip_formatter.format(mouse_x)) && Double.parseDouble(tooltip_formatter.format(dp.mean)) == Double .parseDouble(tooltip_formatter.format(mouse_y))) { for (int j = 0; j < numStocks; j++) text.append("Stock " + (j + 1) + ": x[" + (j + 1) + "]=" + tooltip_formatter.format(dp.x[j]) + " ,"); text.append("\n---\n"); } } } if (!mouseClicked) { mouse_x = minPoint.std; mouse_y = minPoint.mean; } m_serie.add(mouse_x, mouse_y); XYSeriesCollection ds = new XYSeriesCollection(); ds.addSeries(e_serie); ds.addSeries(m_serie); ds.addSeries(b_serie); ds.addSeries(s_serie); JFreeChart chart = ChartFactory.createXYLineChart("", // chart title "Risk (Standard Deviation)", // x axis label "Expected Return", // y axis label ds, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); chart.setBackgroundPaint(Color.white); XYPlot subplot1 = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer1 = (XYLineAndShapeRenderer) subplot1.getRenderer(); renderer1.setSeriesPaint(1, Color.red); renderer1.setSeriesPaint(3, Color.blue); renderer1.setSeriesPaint(2, Color.blue); //grey renderer1.setSeriesPaint(0, Color.blue); //green Shape shape = renderer1.getBaseShape(); renderer1.setSeriesShape(2, shape); renderer1.setSeriesShape(3, shape); renderer1.setBaseLinesVisible(false); renderer1.setBaseShapesVisible(true); renderer1.setBaseShapesFilled(true); chartPanel = new ChartPanel(chart, false); chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y)); chartPanel.addChartMouseListener(this); super.updateGraph(chartPanel); // if (mouseClicked) { getRecordTable().setText(text.toString()); } else { text = new StringBuffer(); text.append("(" + tooltip_formatter.format(minPoint.mean) + " , " + tooltip_formatter.format(minPoint.std) + ")\n"); for (int j = 0; j < numStocks; j++) text.append("Stock " + (j + 1) + ": x[" + (j + 1) + "]=" + tooltip_formatter.format(minPoint.x[j]) + ","); text.append("\n---\n"); getRecordTable().setText(text.toString()); ; } mouseClicked = false; }