List of usage examples for org.jfree.chart ChartFactory createScatterPlot
public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls)
From source file:lu.lippmann.cdb.datasetview.tabs.ScatterPlotTabView.java
private static ChartPanel buildChartPanel(final Instances dataSet, final int xidx, final int yidx, final int coloridx, final boolean asSerie) { final XYSeriesCollection data = new XYSeriesCollection(); final Map<Integer, List<Instance>> filteredInstances = new HashMap<Integer, List<Instance>>(); final int classIndex = dataSet.classIndex(); if (classIndex < 0) { final XYSeries series = new XYSeries("Serie", false); for (int i = 0; i < dataSet.numInstances(); i++) { series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx)); }/* w w w. j a v a 2 s . c o m*/ data.addSeries(series); } else { final Set<String> pvs = WekaDataStatsUtil.getPresentValuesForNominalAttribute(dataSet, classIndex); int p = 0; for (final String pv : pvs) { final XYSeries series = new XYSeries(pv, false); for (int i = 0; i < dataSet.numInstances(); i++) { if (dataSet.instance(i).stringValue(classIndex).equals(pv)) { if (!filteredInstances.containsKey(p)) { filteredInstances.put(p, new ArrayList<Instance>()); } filteredInstances.get(p).add(dataSet.instance(i)); series.add(dataSet.instance(i).value(xidx), dataSet.instance(i).value(yidx)); } } data.addSeries(series); p++; } } final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot", // chart title dataSet.attribute(xidx).name(), // x axis label dataSet.attribute(yidx).name(), // y axis label data, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); final XYPlot xyPlot = (XYPlot) chart.getPlot(); final XYToolTipGenerator gen = new XYToolTipGenerator() { @Override public String generateToolTip(final XYDataset dataset, final int series, final int item) { if (classIndex < 0) { return InstanceFormatter.htmlFormat(dataSet.instance(item), true); } else { return InstanceFormatter.htmlFormat(filteredInstances.get(series).get(item), true); } } }; int nbSeries; if (classIndex < 0) { nbSeries = 1; } else { nbSeries = filteredInstances.keySet().size(); } final XYItemRenderer renderer = new XYLineAndShapeRenderer(asSerie, true) { /** */ private static final long serialVersionUID = 1L; @Override public Paint getItemPaint(final int row, final int col) { //System.out.println(row+" "+col); if (classIndex < 0) { final double v = dataSet.instance(col).value(coloridx); final double[] minmax = WekaDataStatsUtil.getMinMaxForAttributeAsArrayOfDoubles(dataSet, coloridx); final double rated = (v - minmax[0]) / (minmax[1] - minmax[0]); System.out.println("rated -> " + rated + " min=" + minmax[0] + "max=" + minmax[1]); final int colorIdx = (int) Math.round((ColorHelper.YlGnBu_9_COLORS.length - 1) * rated); //System.out.println(minmax[0]+" "+minmax[1]+" "+v+" "+rated+" "+colorIdx); return ColorHelper.YlGnBu_9_COLORS[colorIdx]; } else return super.getItemPaint(row, col); } }; xyPlot.setRenderer(renderer); for (int i = 0; i < nbSeries; i++) { renderer.setSeriesToolTipGenerator(i, gen); } return new ChartPanel(chart); }
From source file:com.joey.software.Launcher.microneedleAnalysis.DataAnalysisViewer.java
public void replotData() { if (modeBox.getSelectedIndex() == MODE_All_FOREARM) { CategoryDataset data = null;/*from w w w . jav a 2s . c o m*/ data = getAllForeArmData(); chartHolder.setChart(ChartFactory.createBarChart("Experiment", "Cat", "Value", data, PlotOrientation.VERTICAL, true, false, false)); } else if (modeBox.getSelectedIndex() == MODE_AVG_FOREARM) { CategoryDataset data = null; data = getAVGForeArmData(); chartHolder.setChart(ChartFactory.createBarChart("Experiment", "Cat", "Value", data, PlotOrientation.VERTICAL, true, false, false)); } else if (modeBox.getSelectedIndex() == MODE_All_FINGER) { XYSeriesCollection collection = getAllFingerData(); chartHolder.setChart(ChartFactory.createScatterPlot("Data", "Time (min)", "Dim", collection, PlotOrientation.VERTICAL, true, false, false)); } }
From source file:stratego.neural.net.StrategoNeuralNet.java
private static void plotDataSet(List<NamedDataSet> ArraySetList, String network_name) { String plot_title = "Plot " + plotIndex + ": Overfitting on network " + network_name; XYSeriesCollection plotData = new XYSeriesCollection(); for (NamedDataSet ns : ArraySetList) { XYSeries series = new XYSeries(ns.getName()); double[] data = ns.getArray(); for (int i = 0; i < data.length; i++) { series.add((double) i, data[i]); }//from w ww . jav a 2s. c o m plotData.addSeries(series); } String title = plot_title; String xAxisLabel = "Epochs"; String yAxisLabel = "Accuracy"; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean legend = true; // might wanna set this to true at some point, but research the library boolean tooltips = false; boolean urls = false; JFreeChart chart = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, plotData, orientation, legend, tooltips, urls); JPanel panel = new ChartPanel(chart); JFrame f = new JFrame(); f.add(panel); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.pack(); f.setTitle(plot_title); f.setVisible(true); plotIndex++; // increase the plotindex }
From source file:net.bioclipse.chart.ChartUtils.java
/** * Displays data in a scatter plot/*from w w w . ja v a 2 s . co m*/ * * @param xValues x values of points * @param yValues y values of points * @param xLabel X axis label * @param yLabel Y axis label * @param title plot title * @param indices * @param dataSource The editor from which the charts data comes from, used so indices are mapped to the right editor */ public static void scatterPlot(double[] xValues, double[] yValues, String xLabel, String yLabel, String title, int[] indices, IEditorPart dataSource) { setupData(xValues, yValues, xLabel, yLabel, title); DefaultXYDataset dataset = new DefaultXYDataset(); dataset.addSeries(1, values); chart = ChartFactory.createScatterPlot(title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, false, false, false); ChartDescriptor descriptor = new ChartDescriptor(dataSource, indices, ChartConstants.SCATTER_PLOT, xLabel, yLabel); chartManager.put(chart, descriptor); view.display(chart); }
From source file:org.hxzon.demo.jfreechart.XYDatasetDemo.java
private static JFreeChart createScatterChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createScatterPlot("Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips? false // URLs? );// w w w .jav a2 s. c o m chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setNumberFormatOverride(MyNumberFormat.getMyNumberFormat()); return chart; }
From source file:web.diva.server.unused.PCAGenerator.java
public PCAImageResult generateChart(String path, PCAResults pcaResults, int[] subSelectionData, int[] selection, boolean zoom, boolean selectAll, String imgName, double w, double h, DivaDataset divaDataset) { XYDataset dataset = this.createDataset(pcaResults.getPoints(), subSelectionData, selection, zoom, divaDataset);/*w ww. j a va 2 s . co m*/ final JFreeChart chart = ChartFactory.createScatterPlot("", // chart title "Principal Component" + (pcaResults.getPcai() + 1), // x axis label "Principal Component " + (pcaResults.getPcaii() + 1), // y axis label dataset, // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); final XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainGridlinePaint(Color.WHITE); plot.setRangeGridlinePaint(Color.WHITE); XYDotRenderer renderer = new XYDotRenderer(); renderer.setDotHeight(5); renderer.setDotWidth(5); if (selectAll) { int i = 0; for (String col : seriesList.keySet()) { if (col.equalsIgnoreCase("unGrouped")) { col = "#000000"; } renderer.setSeriesPaint(i, imgGenerator.hex2Rgb(col)); i++; } } else if (selection == null) { renderer.setPaint(Color.LIGHT_GRAY); int i = 0; for (String col : seriesList.keySet()) { if (col.equalsIgnoreCase("unGrouped")) { col = "#000000"; } renderer.setSeriesPaint(i, imgGenerator.hex2Rgb(col)); i++; } } else { int i = 0; for (String col : seriesList.keySet()) { if (col.equalsIgnoreCase("unGrouped")) { renderer.setSeriesPaint(i, Color.LIGHT_GRAY); } else { renderer.setSeriesPaint(i, imgGenerator.hex2Rgb(col)); } i++; } } plot.setRenderer(renderer); plot.setSeriesRenderingOrder(SeriesRenderingOrder.REVERSE); NumberAxis xAxis = new NumberAxis("Principal Component" + (pcaResults.getPcai() + 1)); xAxis.setVerticalTickLabels(true); boolean auto = xAxis.getAutoRangeIncludesZero(); xAxis.setAutoRangeIncludesZero(true ^ auto); NumberAxis yAxis = new NumberAxis("Principal Component" + (pcaResults.getPcaii() + 1)); yAxis.setAutoRangeIncludesZero(true ^ auto); yAxis.setTickUnit(new NumberTickUnit(1)); plot.setDomainAxis(0, xAxis); plot.setRangeAxis(0, yAxis); double MaxX = xAxis.getRange().getUpperBound(); double MinX = xAxis.getRange().getLowerBound(); double MaxY = yAxis.getRange().getUpperBound(); double MinY = yAxis.getRange().getLowerBound(); chartRenderingInfo.clear(); String imgUrl = imgGenerator.saveToFile(chart, w, h, chartRenderingInfo); PCAImageResult imgUtilRes = new PCAImageResult(); imgUtilRes.setImgString(imgUrl); imgUtilRes.setDataAreaMaxX(chartRenderingInfo.getPlotInfo().getDataArea().getMaxX()); imgUtilRes.setDataAreaMaxY(chartRenderingInfo.getPlotInfo().getDataArea().getMaxY()); imgUtilRes.setDataAreaMinY(chartRenderingInfo.getPlotInfo().getDataArea().getMinY()); imgUtilRes.setDataAreaMinX(chartRenderingInfo.getPlotInfo().getDataArea().getMinX()); imgUtilRes.setMaxX(MaxX); imgUtilRes.setMaxY(MaxY); imgUtilRes.setMinX(MinX); imgUtilRes.setMinY(MinY); return imgUtilRes; }
From source file:jimaginary.machine.set.viewer.SetViewerTopComponent.java
private void createMidiChart(Set set) { if (set == null) { return;// w w w. ja v a2 s. co m } XYSeries series = new XYSeries("Distrbution"); float setValues[] = set.getValues(); for (int i = 0; i < setValues.length; i++) { if ((int) setValues[i] != 0) { series.add(i, (int) setValues[i]); } } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); // Generate the graph JFreeChart chart = ChartFactory.createScatterPlot(set.getName(), "Position", "Note", dataset, PlotOrientation.VERTICAL, // Plot Orientation true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); // add annotations if we have them XYPlot plot = chart.getXYPlot(); for (int i = 0; i < setValues.length; i++) { XYTextAnnotation an = new XYTextAnnotation(MidiCodec.noteValToString((int) setValues[i]), i, (int) setValues[i]); plot.addAnnotation(an); } if (chartPanel != null) { jPanelChart.remove(chartPanel); } chartPanel = new ChartPanel(chart); jPanelChart.setLayout(new java.awt.BorderLayout()); jPanelChart.add(chartPanel, BorderLayout.CENTER); jPanelChart.validate(); }
From source file:org.graphstream.algorithm.measure.ChartConnectivityMeasure.java
public JFreeChart createChart(PlotParameters params) throws PlotException { JFreeChart chart;/*w w w. j av a2s. c o m*/ XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(vertexConnectivity.getXYSeries()); dataset.addSeries(edgeConnectivity.getXYSeries()); switch (params.type) { case LINE: chart = ChartFactory.createXYLineChart(params.title, params.xAxisLabel, params.yAxisLabel, dataset, params.orientation, params.showLegend, false, false); break; case BAR: chart = ChartFactory.createXYBarChart(params.title, params.xAxisLabel, false, params.yAxisLabel, dataset, params.orientation, params.showLegend, false, false); break; case SCATTER: chart = ChartFactory.createScatterPlot(params.title, params.xAxisLabel, params.yAxisLabel, dataset, params.orientation, params.showLegend, false, false); break; default: throw new PlotException("unsupported plot type"); } return chart; }
From source file:com.planetmayo.debrief.satc_rcp.views.SpatialView.java
/** * Creates the Chart based on a dataset//from w ww. ja v a2s. co m * * @param _myData2 */ private JFreeChart createChart(XYDataset _myData2) { // tell it to draw joined series _renderer = new XYLineAndShapeRenderer(true, false); _chart = ChartFactory.createScatterPlot("States", "Lat", "Lon", _myData2, PlotOrientation.HORIZONTAL, true, false, false); _plot = (XYPlot) _chart.getPlot(); _plot.setBackgroundPaint(Color.WHITE); _plot.setDomainCrosshairPaint(Color.LIGHT_GRAY); _plot.setRangeCrosshairPaint(Color.LIGHT_GRAY); _plot.setNoDataMessage("No data available"); _plot.setRenderer(_renderer); _chart.getLegend().setVisible(false); return _chart; }
From source file:GUI.PlotCreator.java
private ChartPanel createSeaCurrentSpeedByTimePanel() { JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "Time(Hours)", "Sea Current Speed", createSeaCurrentSpeedDataByTime(), PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis(); domain.setTickUnit(new NumberTickUnit(1.0)); domain.setVerticalTickLabels(true);/*from w w w .j a v a2 s. co m*/ return new ChartPanel(jfreechart); }