List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer XYLineAndShapeRenderer
public XYLineAndShapeRenderer()
From source file:projects.upc.exec.HrDiagram.java
/** * Update the {@link HrDiagram#chartPanel}. *//* w w w . j a v a2 s.c om*/ private void updateChart() { XYSeries series = new XYSeries("UPC HR diagram"); for (Entry<UpcStar, SsaCrossMatch> xm : starsToPlot.entrySet()) { UpcStar upcStar = xm.getKey(); SsaCrossMatch ssa = xm.getValue(); // Get the SSA colours of the UPC star double b = ssa.ssaB; double r2 = ssa.ssaR2; // double i = ssa.ssaI; // Use the parallax to correct the apparent magnitude to absolute magnitude. // Extract the parallax and error to use double p = (useHip && upcStar.isHipparcosStar()) ? upcStar.srcPi : upcStar.absPi; double sigma_p = (useHip && upcStar.isHipparcosStar()) ? upcStar.srcPiErr : upcStar.absPiErr; // Filter on the fractional parallax error double f = sigma_p / p; if (f > fMax) { continue; } // Correct to arcseconds p /= 1000; sigma_p /= 1000; // Get the distance double d = DistanceFromParallax.getDistance(p, sigma_p, method); // Filter & convert to absolute magnitude if (d > 0 && !Double.isInfinite(d)) { double B = MagnitudeUtils.getAbsoluteMagnitude(d, b); series.add(b - r2, B); } } XYSeriesCollection data = new XYSeriesCollection(); data.addSeries(series); // Set up the renderer XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1)); // Configure axes NumberAxis xAxis = new NumberAxis("B - R [mag]"); xAxis.setRange(-1.0, 3.5); NumberAxis yAxis = new NumberAxis("B [mag]"); yAxis.setInverted(true); yAxis.setRange(-5, 15); // Configure plot XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer); xyplot.setBackgroundPaint(Color.white); JFreeChart chart = new JFreeChart("HR diagram of UPC stars with SSA cross-matches", xyplot); chart.removeLegend(); chart.setBackgroundPaint(Color.white); if (chartPanel == null) { // Branch is used on initialisation chartPanel = new ChartPanel(chart); } else { chartPanel.setChart(chart); } }
From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaLineChartExpression.java
protected void configureLineChart(final XYPlot plot) { final XYDataset linesDataset = createLinesDataset(); if (linesDataset == null || linesDataset.getSeriesCount() == 0) { return;/* www . j a v a 2 s .c om*/ } //Create Axis Objects final ValueAxis linesAxis; if (isSharedRangeAxis()) { linesAxis = plot.getRangeAxis(); } else if (isThreeD()) { linesAxis = new NumberAxis3D(getSecondValueAxisLabel()); } else { linesAxis = new NumberAxis(getSecondValueAxisLabel()); } final XYItemRenderer lineRenderer; if (isThreeD()) { lineRenderer = new XYLine3DRenderer(); } else { lineRenderer = new XYLineAndShapeRenderer(); } plot.setRenderer(1, lineRenderer); plot.setDataset(1, linesDataset); plot.setRangeAxis(1, linesAxis); //map lines to second axis plot.mapDatasetToRangeAxis(1, 1); //set location of second axis plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); }
From source file:com.vgi.mafscaling.VECalc.java
protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) { JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);/*from w w w . jav a 2s.c o m*/ chart.setBorderVisible(true); chartPanel = new ChartPanel(chart, true, true, true, true, true); chartPanel.setAutoscrolls(true); chartPanel.setMouseZoomable(false); GridBagConstraints gbl_chartPanel = new GridBagConstraints(); gbl_chartPanel.anchor = GridBagConstraints.CENTER; gbl_chartPanel.insets = new Insets(3, 3, 3, 3); gbl_chartPanel.weightx = 1.0; gbl_chartPanel.weighty = 1.0; gbl_chartPanel.fill = GridBagConstraints.BOTH; gbl_chartPanel.gridx = 0; gbl_chartPanel.gridy = 1; plotPanel.add(chartPanel, gbl_chartPanel); XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(); lineRenderer.setUseFillPaint(true); lineRenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"))); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f); lineRenderer.setSeriesStroke(0, stroke); lineRenderer.setSeriesPaint(0, Color.RED); lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5)); lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() { private static final long serialVersionUID = 7593430826693873496L; public String generateLabel(XYDataset dataset, int series) { XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series); return xys.getDescription(); } }); NumberAxis xAxis = new NumberAxis(xAxisName); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisName); yAxis.setAutoRangeIncludesZero(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); XYPlot plot = chart.getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDataset(0, lineDataset); plot.setRenderer(0, lineRenderer); plot.setDomainAxis(0, xAxis); plot.setRangeAxis(0, yAxis); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); chart.addLegend(legend); }
From source file:edu.cmu.sv.modelinference.eventtool.EventVisualizer.java
private void visualizeFeatures(ClassificationResult classes, Map<EventClass, Color> clusterColors, List<Range<Integer>> violations, int timeStepSize, DefaultXYDataset rawDataSet, DefaultXYDataset featuresDataSet) { //Get chart on which we will plot the features and violations DataChart c = new DataChart("Features chart"); JFreeChart chart = c.chart(""); //Plot violations XYPlot plot = chart.getXYPlot();/*from www .jav a 2 s . c o m*/ plot.setDataset(0, rawDataSet); plot.setRenderer(0, new ClassificationXYRenderer(classes, timeStepSize, clusterColors)); plot.setDataset(1, featuresDataSet); plot.setRenderer(1, new XYLineAndShapeRenderer()); setViolationMarkers(violations, plot); c.pack(); RefineryUtilities.centerFrameOnScreen(c); c.setVisible(true); }
From source file:dumbara.view.Chart1.java
public static void ViewLineChart(String[] agencyID, String[] sslesDate, ArrayList<String[]> arrayList) throws SQLException, ClassNotFoundException { XYSeries series1 = new XYSeries("Agency 1"); XYSeries series2 = new XYSeries("Agency 2"); XYSeries series3 = new XYSeries("Agency 3"); XYSeries series4 = new XYSeries("Agency 4"); for (String[] strings : arrayList) { for (int i = 0; i < sslesDate.length; i++) { System.out.println(sslesDate[i].split("-")[1] + ""); series1.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(0)[i])); }//w w w .jav a 2 s. c om for (int i = 0; i < sslesDate.length; i++) { series2.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(1)[i])); } for (int i = 0; i < sslesDate.length; i++) { series3.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(2)[i])); } for (int i = 0; i < sslesDate.length; i++) { series4.add(Double.parseDouble(sslesDate[i].split("-")[1] + ""), Double.parseDouble(arrayList.get(3)[i])); } } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series1); dataset.addSeries(series2); dataset.addSeries(series3); dataset.addSeries(series4); XYDataset dataset1 = dataset; JFreeChart chart = ChartFactory.createXYLineChart("", "Test Id", "Average Marks", dataset1, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesLinesVisible(1, true); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(2, true); renderer.setSeriesShapesVisible(2, true); renderer.setSeriesFillPaint(2, Color.MAGENTA); plot.setRenderer(renderer); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 300)); //(chartPanel); ChartFrame frame = new ChartFrame("Dumbara Water Management System", chart); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true); }
From source file:org.gephi.ui.utils.ChartsUtils.java
/** * Modify a scatter plot to show lines instead or shapes or not. * @param scatterPlot Scatter plot to modify * @param enabled Indicates if lines have to be shown */// w ww . j av a 2s . c o m public static void setScatterPlotLinesEnabled(final JFreeChart scatterPlot, final boolean enabled) { XYPlot plot = (XYPlot) scatterPlot.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); if (enabled) { renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); } else { renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShapesVisible(0, true); renderer.setSeriesShape(0, new java.awt.geom.Ellipse2D.Double(0, 0, 1, 1)); } renderer.setSeriesPaint(0, Color.RED); plot.setRenderer(0, renderer); }
From source file:sentimentanalyzer.ChartController.java
public void postTheTimeSeriesChartOnTheGUI_sentiment(JPanel timeSeriesChart, XYSeriesCollection dataset, String title, String y, String x, int row) { this.wordSentimentScore = ChartFactory.createXYLineChart(title, y, x, dataset, PlotOrientation.VERTICAL, true, true, false);// ww w . ja va 2s . c o m this.wordIndexesOnGraph.add(row); this.plot_sentiment = this.wordSentimentScore.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); //CHECK THIS renderer.setBaseShapesVisible(true); this.plot_sentiment.setRenderer(renderer); this.plot_sentiment.setOutlinePaint(Color.orange); NumberAxis rangeAxis = (NumberAxis) this.plot_sentiment.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); NumberAxis domainAxis = (NumberAxis) this.plot_sentiment.getDomainAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); this.wordSentimentScore.setBackgroundPaint(Color.white); this.wordSentimentScore.setBorderPaint(Color.ORANGE); ChartPanel CP = new ChartPanel(this.wordSentimentScore); timeSeriesChart.setLayout(new java.awt.BorderLayout()); timeSeriesChart.add(CP, BorderLayout.CENTER); timeSeriesChart.revalidate(); }
From source file:oct.analysis.application.OCTSelection.java
public JPanel createLRPPanel() { //create the series collection from the LRP data XYSeriesCollection lrp = new XYSeriesCollection(); lrp.addSeries(getLrpSeriesFromOCT(OCTAnalysisManager.getInstance().getOctImage())); // System.out.println("Processing graph " + lrp.getSeriesKey(0).toString()); lrp.addSeries(findMaximums(lrp.getSeries(0), selectionName + " LRP Maximums")); List<XYSeries> fwhm = getFWHMForLRPPeaks(lrp.getSeries(1), lrp.getSeries(0)); fwhm.forEach((fwhmSeries) -> {//from w ww. ja v a2 s.com lrp.addSeries(fwhmSeries); }); //create chart panel for LRP JFreeChart chart = ChartFactory.createXYLineChart(lrp.getSeriesKey(0).toString(), "Pixel Height", "Reflectivity", lrp, PlotOrientation.HORIZONTAL, false, true, false); XYPlot plot = chart.getXYPlot(); // plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // plot.getDomainAxis().setInverted(true); //set up rendering principles XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesShapesFilled(1, true); renderer.setSeriesPaint(1, Color.BLUE); for (int i = 2; i < fwhm.size() + 2; i++) { renderer.setSeriesLinesVisible(i, true); renderer.setSeriesShapesVisible(i, false); renderer.setSeriesPaint(i, Color.BLACK); } plot.setRenderer(renderer); //make panel ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(200, 200)); panel.setFillZoomRectangle(true); panel.setMouseWheelEnabled(true); return panel; }
From source file:com.android.ddmuilib.log.event.DisplayGraph.java
/** * Returns a {@link TimeSeriesCollection} for a specific {@link com.android.ddmlib.log.EventValueDescription.ValueType}. * If the data set is not yet created, it is first allocated and set up into the * {@link org.jfree.chart.JFreeChart} object. * @param type the {@link com.android.ddmlib.log.EventValueDescription.ValueType} of the data set. * @param accumulateValues/*from ww w .j av a 2 s.c om*/ */ private TimeSeriesCollection getValueDataset(EventValueDescription.ValueType type, boolean accumulateValues) { TimeSeriesCollection dataset = mValueTypeDataSetMap.get(type); if (dataset == null) { // create the data set and store it in the map dataset = new TimeSeriesCollection(); mValueTypeDataSetMap.put(type, dataset); // create the renderer and configure it depending on the ValueType AbstractXYItemRenderer renderer; if (type == EventValueDescription.ValueType.PERCENT && accumulateValues) { renderer = new XYAreaRenderer(); } else { XYLineAndShapeRenderer r = new XYLineAndShapeRenderer(); r.setBaseShapesVisible(type != EventValueDescription.ValueType.PERCENT); renderer = r; } // set both the dataset and the renderer in the plot object. XYPlot xyPlot = mChart.getXYPlot(); xyPlot.setDataset(mDataSetCount, dataset); xyPlot.setRenderer(mDataSetCount, renderer); // put a new axis label, and configure it. NumberAxis axis = new NumberAxis(type.toString()); if (type == EventValueDescription.ValueType.PERCENT) { // force percent range to be (0,100) fixed. axis.setAutoRange(false); axis.setRange(0., 100.); } // for the index, we ignore the occurrence dataset int count = mDataSetCount; if (mOccurrenceDataSet != null) { count--; } xyPlot.setRangeAxis(count, axis); if ((count % 2) == 0) { xyPlot.setRangeAxisLocation(count, AxisLocation.BOTTOM_OR_LEFT); } else { xyPlot.setRangeAxisLocation(count, AxisLocation.TOP_OR_RIGHT); } // now we link the dataset and the axis xyPlot.mapDatasetToRangeAxis(mDataSetCount, count); mDataSetCount++; } return dataset; }
From source file:asl.util.PlotMaker.java
public void plotPSD(double per[], double[] model, double[] nhnmPer, double[] nhnm, double[] psd, String modelName, String plotString) { // plotTitle = "2012074.IU_ANMO.00-BHZ " + plotString final String plotTitle = String.format("%04d%03d.%s.%s %s", date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); // plot filename = "2012074.IU_ANMO.00-BHZ" + plotString + ".png" final String pngName = String.format("%s/%04d%03d.%s.%s.%s.png", outputDir, date.get(Calendar.YEAR), date.get(Calendar.DAY_OF_YEAR), station, channel, plotString); File outputFile = new File(pngName); // Check that we will be able to output the file without problems and if not --> return if (!checkFileOut(outputFile)) { System.out.format(/* w w w. j a v a 2 s . c o m*/ "== plotPSD: request to output plot=[%s] but we are unable to create it " + " --> skip plot\n", pngName); return; } Boolean plotNHNM = false; //if (nhnm.length > 0) { if (nhnm != null) { plotNHNM = true; } final XYSeries series1 = new XYSeries(modelName); final XYSeries series2 = new XYSeries(channel.toString()); final XYSeries series3 = new XYSeries("NHNM"); for (int k = 0; k < per.length; k++) { series1.add(per[k], model[k]); series2.add(per[k], psd[k]); } if (plotNHNM) { for (int k = 0; k < nhnmPer.length; k++) { series3.add(nhnmPer[k], nhnm[k]); } } //final XYItemRenderer renderer = new StandardXYItemRenderer(); final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); Rectangle rectangle = new Rectangle(3, 3); renderer.setSeriesShape(0, rectangle); renderer.setSeriesShapesVisible(0, false); renderer.setSeriesLinesVisible(0, true); renderer.setSeriesShape(1, rectangle); renderer.setSeriesShapesVisible(1, true); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShape(2, rectangle); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesLinesVisible(2, true); Paint[] paints = new Paint[] { Color.blue, Color.red, Color.black }; renderer.setSeriesPaint(0, paints[0]); renderer.setSeriesPaint(1, paints[1]); renderer.setSeriesPaint(2, paints[2]); final NumberAxis rangeAxis1 = new NumberAxis("PSD 10log10(m**2/s**4)/Hz dB"); //rangeAxis1.setRange( new Range(-190, -120)); rangeAxis1.setRange(new Range(-190, -95)); rangeAxis1.setTickUnit(new NumberTickUnit(5.0)); final LogarithmicAxis horizontalAxis = new LogarithmicAxis("Period (sec)"); horizontalAxis.setRange(new Range(0.05, 10000)); final XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(series1); seriesCollection.addSeries(series2); if (plotNHNM) { seriesCollection.addSeries(series3); } final XYPlot xyplot = new XYPlot((XYDataset) seriesCollection, horizontalAxis, rangeAxis1, renderer); xyplot.setDomainGridlinesVisible(true); xyplot.setRangeGridlinesVisible(true); xyplot.setRangeGridlinePaint(Color.black); xyplot.setDomainGridlinePaint(Color.black); final JFreeChart chart = new JFreeChart(xyplot); chart.setTitle(new TextTitle(plotTitle)); try { ChartUtilities.saveChartAsPNG(outputFile, chart, 500, 300); } catch (IOException e) { System.err.println("Problem occurred creating chart."); } }