List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer getBaseShape
public Shape getBaseShape()
From source file:edu.ucla.stat.SOCR.applications.demo.BlackScholesApplication.java
void updateGraph() { //System.out.println("UpdateGraph get called") calculate();// w w w .ja v a 2 s. 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.PortfolioApplication.java
void updateGraph() { //System.out.println("UpdateGraph get called"); setupStockOptions();//ww w . j a va 2s .co m 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; }
From source file:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication2.java
void updateGraph() { /* System.out.println("updateGraph get called----------------mouseClicked="+mouseClicked); Exception e = new Exception();//from w ww.j a v a 2s . c om e.printStackTrace();*/ // printMatrix(COVR, "after COVR"); // printMatrix(CORR, "after CORR"); //setupStockOptions(); p_serie = new XYSeries("Stock", false); t_serie = new XYSeries("Tangent", false); m_serie = new XYSeries("M", false); s_serie = new XYSeries("Positives", false); StringBuffer text = new StringBuffer(); text.append("mouse clicked at (Risk, Expected Return) = " + tooltip + "\n"); // text.append("The stock combinations are:"); for (int i = 0; i < chartDataPoints.getPointCount(); i++) { double point_x = chartDataPoints.getX(i); double point_y = chartDataPoints.getY(i); p_serie.add(point_x, point_y); // System.out.println("chart point " +(i+1)+" is ("+point_x+", "+point_y+")"); if (isAllPositive(chartDataPoints.getSDPpointer(i))) { s_serie.add(point_x, point_y); } } if (show_tangent) { t_serie.add(t1_x, t1_y); t_serie.add(t2_x, t2_y); } if (mouseClicked) { // System.out.println("mouse_x="+mouse_x+", mouse_y="+mouse_y); m_serie.add(mouse_x, mouse_y); } XYSeriesCollection ds = new XYSeriesCollection(); ds.addSeries(m_serie); ds.addSeries(t_serie); ds.addSeries(s_serie); ds.addSeries(p_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(); NumberAxis xAxis = (NumberAxis) subplot1.getDomainAxis(); NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis(); if (t2_x > 0) xAxis.setRange(0, t2_x); else xAxis.setRange(t2_x, 0); if (t2_y > 0) yAxis.setRange(-t2_y, t2_y); else yAxis.setRange(t2_y, -t2_y); renderer1.setSeriesPaint(3, Color.blue); renderer1.setSeriesPaint(2, Color.red); renderer1.setSeriesPaint(1, Color.red); renderer1.setSeriesPaint(0, Color.green); Shape shape = renderer1.getBaseShape(); renderer1.setSeriesShape(1, shape); renderer1.setSeriesShape(3, shape); renderer1.setSeriesLinesVisible(0, false); renderer1.setSeriesLinesVisible(1, true); renderer1.setSeriesLinesVisible(2, false); renderer1.setSeriesLinesVisible(3, false); // renderer1.setLinesVisible(); renderer1.setBaseShapesVisible(true); renderer1.setBaseShapesFilled(true); graphPanel.removeAll(); chartPanel = new ChartPanel(chart, false); chartPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y)); chartPanel.addChartMouseListener(this); graphPanel.add(chartPanel); graphPanel.validate(); // 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])+"\n"); text.append("---\n");*/ getRecordTable().setText(text.toString()); ; } mouseClicked = false; }