List of usage examples for org.jfree.chart ChartPanel getChart
public JFreeChart getChart()
From source file:org.jax.bham.util.JFreeChartUtil.java
/** * Convert from a Java2D point to a graph point * @param java2DPoint// w w w .j av a2s .co m * the java 2D point to convert * @param chartPanel * the chart panel to convert * @return * the point */ public static Point2D java2DPointToGraphPoint(Point2D java2DPoint, ChartPanel chartPanel) { JFreeChart chart = chartPanel.getChart(); ChartRenderingInfo info = chartPanel.getChartRenderingInfo(); Rectangle2D dataArea = info.getPlotInfo().getDataArea(); XYPlot xyPlot = chart.getXYPlot(); double graphX = xyPlot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea, xyPlot.getDomainAxisEdge()); double graphY = xyPlot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea, xyPlot.getRangeAxisEdge()); return new Point2D.Double(graphX, graphY); }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumChartFactory.java
public static void setColors(ChartPanel panel, Color[] colors) { Plot plot = panel.getChart().getPlot(); if (plot instanceof XYPlot) { setColors((XYPlot) plot, colors); return;//from www. jav a 2 s . c o m } CombinedDomainXYPlot plotCombined = (CombinedDomainXYPlot) plot; java.util.List list = (plotCombined).getSubplots(); for (int i = 0; i < list.size(); i++) setColors((XYPlot) list.get(i), colors); }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java
public static ChartPanel buildGapChartPanel(final Instances dataSet, final int dateIdx, final Attribute attr, final int gapsize, final int position) throws Exception { Instances filteredDs = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSet, new int[] { attr.index(), dateIdx }); filteredDs = WekaDataProcessingUtil.buildFilteredDataSet(filteredDs, 0, filteredDs.numAttributes() - 1, Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize), Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize, filteredDs.numInstances() - 1)); final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(filteredDs, false, WekaDataStatsUtil.getFirstDateAttributeIdx(filteredDs), null); final XYPlot xyp = (XYPlot) cp.getChart().getPlot(); xyp.getDomainAxis().setLabel(""); xyp.getRangeAxis().setLabel(""); final Marker gapBeginMarker = new ValueMarker(dataSet.instance(Math.max(0, position - 1)).value(dateIdx)); gapBeginMarker.setPaint(Color.RED); gapBeginMarker.setLabel("Gap begin"); gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker); final Marker gapEndMarker = new ValueMarker( dataSet.instance(Math.min(dataSet.numInstances() - 1, position + gapsize)).value(dateIdx)); gapEndMarker.setPaint(Color.RED); gapEndMarker.setLabel("Gap end"); gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT); cp.getChart().getXYPlot().addDomainMarker(gapEndMarker); addExportPopupMenu(filteredDs, cp);// w ww . j a v a2 s . com return cp; }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsUIUtil.java
public static ChartPanel buildGapChartPanelWithCorrection(final Instances pdataSet, final int dateIdx, final Attribute attr, final int gapsize, final int position, final GapFiller gapFiller, final java.util.Collection<String> attrs) throws Exception { final Instances dataSetWithTheGap = new Instances(pdataSet); for (int i = position; i < position + gapsize; i++) dataSetWithTheGap.instance(i).setMissing(attr); int[] arr = new int[] { attr.index(), dateIdx }; for (final String sss : attrs) { arr = ArraysUtil.concat(arr, new int[] { dataSetWithTheGap.attribute(sss).index() }); }//from w ww . j a v a 2s . com Instances filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSetWithTheGap, arr); filteredDsWithTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithTheGap, 0, filteredDsWithTheGap.numAttributes() - 1, Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize), Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize, filteredDsWithTheGap.numInstances() - 1)); final Instances completedds = gapFiller.fillGaps(filteredDsWithTheGap); final Instances diff = WekaTimeSeriesUtil.buildDiff(filteredDsWithTheGap, completedds); Instances filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(pdataSet, arr); filteredDsWithoutTheGap = WekaDataProcessingUtil.buildFilteredDataSet(filteredDsWithoutTheGap, 0, filteredDsWithoutTheGap.numAttributes() - 1, Math.max(0, position - GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize), Math.min(position + gapsize + GapsUtil.VALUES_BEFORE_AND_AFTER_RATIO * gapsize, filteredDsWithoutTheGap.numInstances() - 1)); diff.insertAttributeAt(new Attribute(attr.name() + "_orig"), diff.numAttributes()); for (int i = 0; i < filteredDsWithoutTheGap.numInstances(); i++) { diff.instance(i).setValue(diff.numAttributes() - 1, filteredDsWithoutTheGap.instance(i).value(filteredDsWithoutTheGap.attribute(attr.name()))); } //System.out.println(attr.name()+"\n"+diff.toSummaryString()); final java.util.List<String> toRemove = new java.util.ArrayList<String>(); for (int j = 0; j < diff.numAttributes(); j++) { final String consideredAttrName = diff.attribute(j).name(); if (!consideredAttrName.contains("timestamp") && !consideredAttrName.contains(attr.name())) toRemove.add(consideredAttrName); } diff.setClassIndex(-1); for (final String ssss : toRemove) diff.deleteAttributeAt(diff.attribute(ssss).index()); //System.out.println(attr.name()+"\n"+diff.toSummaryString()); final ChartPanel cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(diff, false, WekaDataStatsUtil.getFirstDateAttributeIdx(diff), null); final XYPlot xyp = (XYPlot) cp.getChart().getPlot(); xyp.getDomainAxis().setLabel(""); xyp.getRangeAxis().setLabel(""); final Marker gapBeginMarker = new ValueMarker( dataSetWithTheGap.instance(Math.max(0, position - 1)).value(dateIdx)); gapBeginMarker.setPaint(Color.RED); gapBeginMarker.setLabel("Gap begin"); gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT); gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker); final Marker gapEndMarker = new ValueMarker(dataSetWithTheGap .instance(Math.min(dataSetWithTheGap.numInstances() - 1, position + gapsize)).value(dateIdx)); gapEndMarker.setPaint(Color.RED); gapEndMarker.setLabel("Gap end"); gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT); cp.getChart().getXYPlot().addDomainMarker(gapEndMarker); addExportPopupMenu(diff, cp); return cp; }
From source file:net.sf.mzmine.chartbasics.graphicsexport.ChartExportUtil.java
/** * Add export dialog to popup menu of a chartpanel * /*from w ww. j ava2 s.c o m*/ * @param plotChartPanel */ public static void addExportDialogToMenu(final ChartPanel cp) { JMenuItem exportGraphics = new JMenuItem("Export graphics..."); exportGraphics.addActionListener(e -> GraphicsExportDialog.openDialog(cp.getChart())); // add to menu cp.getPopupMenu().add(exportGraphics); }
From source file:utils.ChartUtils.java
/** * Update XY chart// www. j a va 2 s. c om * * @param plot ChartPanel Plot * @param sortedArray Sorted array of values */ public static void updateXYChart(ChartPanel plot, double[] sortedArray) { XYPlot xyplot = plot.getChart().getXYPlot(); double min = sortedArray[0]; double max = sortedArray[sortedArray.length - 1]; double median = Utils.getMedian(sortedArray); double q1 = Utils.getQ1(sortedArray); double q3 = Utils.getQ3(sortedArray); XYTextAnnotation annotation; //min-lowlimit horizontal XYSeries serie15 = new XYSeries("15"); serie15.add(min, 0.5); //max-toplimit horizontal XYSeries serie16 = new XYSeries("16"); serie16.add(max, 0.5); //min vertical XYSeries serie1 = new XYSeries("0"); serie1.add(min, 0.45); serie1.add(min, 0.55); annotation = new XYTextAnnotation("Min", min, 0.40); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); //min-q1 horizontal XYSeries serie2 = new XYSeries("1"); serie2.add(min, 0.5); serie2.add(q1, 0.5); //q1 vertical XYSeries serie3 = new XYSeries("2"); serie3.add(q1, 0.1); serie3.add(q1, 0.9); annotation = new XYTextAnnotation("Q1", q1, 0.08); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); // median XYSeries serie_mediana = new XYSeries("11"); serie_mediana.add(median, 0.1); serie_mediana.add(median, 0.9); annotation = new XYTextAnnotation("Median", median, 0.04); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); //q1-q3 horizontal sup XYSeries serie4 = new XYSeries("3"); serie4.add(q1, 0.9); serie4.add(q3, 0.9); //q1-q3 horizontal inf XYSeries serie5 = new XYSeries("4"); serie5.add(q1, 0.1); serie5.add(q3, 0.1); //q3 vertical XYSeries serie6 = new XYSeries("5"); serie6.add(q3, 0.1); serie6.add(q3, 0.9); annotation = new XYTextAnnotation("Q3", q3, 0.08); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); //q3-max horizontal XYSeries serie7 = new XYSeries("6"); serie7.add(q3, 0.5); serie7.add(max, 0.5); //max vertical XYSeries serie8 = new XYSeries("7"); serie8.add(max, 0.45); serie8.add(max, 0.55); annotation = new XYTextAnnotation("Max", max, 0.4); annotation.setFont(new Font("SansSerif", Font.PLAIN, 11)); xyplot.addAnnotation(annotation); XYSeriesCollection xyseriescollection = new XYSeriesCollection(); xyseriescollection.addSeries(serie1); xyseriescollection.addSeries(serie2); xyseriescollection.addSeries(serie3); xyseriescollection.addSeries(serie4); xyseriescollection.addSeries(serie5); xyseriescollection.addSeries(serie6); xyseriescollection.addSeries(serie7); xyseriescollection.addSeries(serie8); xyseriescollection.addSeries(serie15); xyseriescollection.addSeries(serie16); xyseriescollection.addSeries(serie_mediana); xyplot.getRenderer().setSeriesPaint(9, Color.black); xyplot.getRenderer().setSeriesPaint(10, Color.black); xyplot.getRenderer().setSeriesPaint(0, Color.black); xyplot.getRenderer().setSeriesPaint(1, Color.black); xyplot.getRenderer().setSeriesPaint(2, Color.black); xyplot.getRenderer().setSeriesPaint(3, Color.black); xyplot.getRenderer().setSeriesPaint(4, Color.black); xyplot.getRenderer().setSeriesPaint(5, Color.black); xyplot.getRenderer().setSeriesPaint(6, Color.black); xyplot.getRenderer().setSeriesPaint(7, Color.black); xyplot.getRenderer().setSeriesPaint(8, Color.black); xyplot.getRenderer().setSeriesPaint(9, Color.black); xyplot.getRenderer().setSeriesPaint(10, Color.black); xyplot.getRenderer().setSeriesPaint(11, Color.black); xyplot.getRenderer().setSeriesPaint(12, Color.black); xyplot.getRenderer().setSeriesPaint(13, Color.black); //add dataset xyplot.setDataset(xyseriescollection); // add a second dataset and renderer... XYSeriesCollection anotherserie = new XYSeriesCollection(); XYSeries serie_point = new XYSeries("21"); double[] yValue = { 0.47, 0.49, 0.51, 0.53 }; for (int i = 0, j = 0; i < sortedArray.length; i++, j++) { if (j % 4 == 0) { j = 0; } serie_point.add(sortedArray[i], yValue[j]); } anotherserie.addSeries(serie_point); XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(false, true); renderer1.setSeriesPaint(0, Color.lightGray); xyplot.setDataset(1, anotherserie); xyplot.setRenderer(1, renderer1); }
From source file:edu.jhuapl.graphs.jfreechart.utils.HighResChartUtil.java
/** * Returns a high resolution BufferedImage of the chart. Uses the default DPI_FILE_RESOLUTION. * * @param resolution The resolution, in dots per inch, of the image to generate. * @return the buffered image./*from www. j ava 2 s.c o m*/ */ public static BufferedImage getHighResChartImage(ChartPanel chartPanel, int resolution) { int screenResolution = Toolkit.getDefaultToolkit().getScreenResolution(); double scaleRatio = resolution / screenResolution; int width = chartPanel.getWidth(); int height = chartPanel.getHeight(); int rasterWidth = (int) (width * scaleRatio); int rasterHeight = (int) (height * scaleRatio); BufferedImage image = new BufferedImage(rasterWidth, rasterHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.transform(AffineTransform.getScaleInstance(scaleRatio, scaleRatio)); chartPanel.getChart().draw(g2, new Rectangle2D.Double(0, 0, width, height), null); g2.dispose(); return image; }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * //from w w w . j a v a 2 s. com * @param myChart * @return Range the domainAxis zoom (X-axis) */ public static Range getZoomDomainAxis(ChartPanel myChart) { XYPlot plot = (XYPlot) myChart.getChart().getPlot(); ValueAxis domainAxis = plot.getDomainAxis(); return new Range(domainAxis.getLowerBound(), domainAxis.getUpperBound()); }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Auto range the range axis/*from w w w . ja v a 2s. c o m*/ * * @param myChart * @param zoom * @param autoRangeY if true the range (Y) axis auto bounds will be restored */ public static void autoRangeAxis(ChartPanel myChart) { XYPlot plot = (XYPlot) myChart.getChart().getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); // trick. Otherwise auto range will fail sometimes rangeAxis.setRange(rangeAxis.getRange()); rangeAxis.setAutoRangeIncludesZero(true); myChart.restoreAutoRangeBounds(); }
From source file:net.sf.mzmine.chartbasics.ChartLogics.java
/** * Auto range the range axis/* w w w . j a v a 2s.c o m*/ * * @param myChart * @param zoom * @param autoRangeY if true the range (Y) axis auto bounds will be restored */ public static void autoDomainAxis(ChartPanel myChart) { XYPlot plot = (XYPlot) myChart.getChart().getPlot(); NumberAxis axis = (NumberAxis) plot.getDomainAxis(); // trick. Otherwise auto range will fail sometimes axis.setRange(axis.getRange()); axis.setAutoRangeIncludesZero(false); myChart.restoreAutoDomainBounds(); }