/** * Constructor: initialize the plot & chart * @param title */ public ScatterPlot (String title) { data = new ScatterData(); chart = ChartFactory.createScatterPlot(title, "X", "Y", new DefaultXYDataset(), PlotOrientation.VERTICAL, false,false,false); chart.setBackgroundPaint(Color.white); chart.setBorderVisible(false); plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setOutlineVisible(false); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); this.configAxes(); }
public void lineGraph() { final LengthDataset dataset = new LengthDataset(this.eventBus); final JFreeChart chart = ChartFactory.createXYLineChart("", "Iteration", "Length", dataset, PlotOrientation.VERTICAL, true, false, true); final XYPlot plot = chart.getXYPlot(); plot.setDataset(1, new FittnessDataset(this.eventBus)); plot.mapDatasetToRangeAxis(1, 1); final XYItemRenderer renderer2 = new XYLineAndShapeRenderer(true, false); plot.setRenderer(1, renderer2); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); final ValueAxis axis2 = new NumberAxis("Fittness"); plot.setRangeAxis(1, axis2); final ChartPanel panel = new ChartPanel(chart); final JFrame jFrame = new JFrame(); jFrame.setContentPane(panel); jFrame.pack(); jFrame.setVisible(true); }
protected void paint( PPaintContext paintContext ) { Graphics2D g2 = paintContext.getGraphics(); if ( _renderingHints != null ) { g2.setRenderingHints( _renderingHints ); } // Clip to the data area. // Do NOT call g2.setClip, or really bad things happen // with drawing order on Macintosh (and possibly other platforms). paintContext.pushClip( _dataArea ); // Render each of the plot's datasets, in the proper order... int numberOfDatasets = _plot.getDatasetCount(); DatasetRenderingOrder renderingOrder = _plot.getDatasetRenderingOrder(); if ( renderingOrder == DatasetRenderingOrder.FORWARD ) { for ( int i = 0; i < numberOfDatasets; i++ ) { _plot.render( g2, _dataArea, i, null, null ); } } else { /* DatasetRenderingOrder.REVERSE */ for ( int i = numberOfDatasets - 1; i >= 0; i-- ) { _plot.render( g2, _dataArea, i, null, null ); } } // restore the clip paintContext.popClip( null ); // optionally stroke the data area -- do this after restoring the clip if ( _dataAreaStroked ) { g2.setStroke( _plot.getOutlineStroke() ); g2.setPaint( _plot.getOutlinePaint() ); g2.draw( _dataArea ); } }
private void addDatasetToPlot(XYPlot xyPlot, XYDataset xyDataset) { int index = xyPlot.getDatasetCount(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); for (int i = 0, size = xyDataset.getSeriesCount(); i < size; ++i) { renderer.setSeriesShapesVisible(i, false); renderer.setSeriesStroke(i, new BasicStroke(1.5f)); } xyPlot.setRenderer(index, renderer); xyPlot.setDataset(index, xyDataset); xyPlot.mapDatasetToRangeAxis(index, 0); xyPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); }
/** * Returns a CategoryPlot. */ private CategoryPlot getCategoryPlot( CategoryDataset dataSet, CategoryItemRenderer renderer, PlotOrientation orientation, CategoryLabelPositions labelPositions ) { CategoryPlot plot = new CategoryPlot( dataSet, new CategoryAxis(), new NumberAxis(), renderer ); plot.setDatasetRenderingOrder( DatasetRenderingOrder.FORWARD ); plot.setOrientation( orientation ); CategoryAxis xAxis = plot.getDomainAxis(); xAxis.setCategoryLabelPositions( labelPositions ); return plot; }
private JFreeChart createChart() { if (data.getItemCount() > 0) { // get cumulative percentages KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset( "Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(null, // chart title this.dataTable.getColumnName(this.groupByColumn), // domain axis label "Count", // range axis label categoryDataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); // get a reference to the plot for further customization... CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); // second data set (cumulative percentages) CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker()); NumberAxis axis2 = new NumberAxis("Percent of " + countValue); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis2.setLabelFont(LABEL_FONT_BOLD); axis2.setTickLabelFont(LABEL_FONT); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); axis2.setTickUnit(new NumberTickUnit(0.1)); // show grid lines plot.setRangeGridlinesVisible(true); // bring cumulative line to front plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); if (isLabelRotating()) { domainAxis.setTickLabelsVisible(true); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } return chart; } else { return null; } }
public static void main(String[] args) { /** * Getting time series */ TimeSeries series = CsvTradesLoader.loadBitstampSeries(); /** * Creating the OHLC dataset */ OHLCDataset ohlcDataset = createOHLCDataset(series); /** * Creating the additional dataset */ TimeSeriesCollection xyDataset = createAdditionalDataset(series); /** * Creating the chart */ JFreeChart chart = ChartFactory.createCandlestickChart( "Bitstamp BTC price", "Time", "USD", ohlcDataset, true); // Candlestick rendering CandlestickRenderer renderer = new CandlestickRenderer(); renderer.setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_SMALLEST); XYPlot plot = chart.getXYPlot(); plot.setRenderer(renderer); // Additional dataset int index = 1; plot.setDataset(index, xyDataset); plot.mapDatasetToRangeAxis(index, 0); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false); renderer2.setSeriesPaint(index, Color.blue); plot.setRenderer(index, renderer2); // Misc plot.setRangeGridlinePaint(Color.lightGray); plot.setBackgroundPaint(Color.white); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setAutoRangeIncludesZero(false); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); /** * Displaying the chart */ displayChart(chart); }
public void GeneratePlot(String pngfile) throws IOException { String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile) + "_ModelPoints.txt"; FileWriter writer = new FileWriter(modelfile); double[] IDObs = new double[IDEmpiricalDist.getN()]; double[] DecoyObs = new double[DecoyEmpiricalDist.getN()]; for (int i = 0; i < IDEmpiricalDist.getN(); i++) { IDObs[i] = IDEmpiricalDist.getObs(i); } for (int i = 0; i < DecoyEmpiricalDist.getN(); i++) { DecoyObs[i] = DecoyEmpiricalDist.getObs(i); } XYSeries model1 = new XYSeries("Incorrect matches"); XYSeries model2 = new XYSeries("Correct matches"); XYSeries model3 = new XYSeries("All target hits"); writer.write("UScore\tModel\tCorrect\tDecoy\n"); for (int i = 0; i < NoBinPoints; i++) { model1.add(model_kde_x[i], decoy_kde_y[i]); model2.add(model_kde_x[i], correct_kde_y[i]); model3.add(model_kde_x[i], model_kde_y[i]); writer.write(model_kde_x[i] + "\t" + model_kde_y[i] + "\t" + correct_kde_y[i] + "\t" + decoy_kde_y[i] + "\n"); } writer.close(); MixtureModelProb = new Float[NoBinPoints + 1][3]; float positiveaccu = 0f; float negativeaccu = 0f; MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE; MixtureModelProb[0][1] = 1f; MixtureModelProb[0][2] = 1f; for (int i = 1; i < NoBinPoints + 1; i++) { double positiveNumber = correct_kde_y[NoBinPoints - i]; double negativeNumber = decoy_kde_y[NoBinPoints - i]; MixtureModelProb[i][0] = (float) model_kde_x[NoBinPoints - i]; positiveaccu += positiveNumber; negativeaccu += negativeNumber; MixtureModelProb[i][2] = 0.999999f * (float) (positiveNumber / (negativeNumber + positiveNumber)); MixtureModelProb[i][1] = 0.999999f * (float) (positiveaccu / (negativeaccu + positiveaccu)); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(model1); dataset.addSeries(model2); dataset.addSeries(model3); HistogramDataset histogramDataset = new HistogramDataset(); histogramDataset.setType(HistogramType.SCALE_AREA_TO_1); histogramDataset.addSeries("ID hits", IDObs, 100); histogramDataset.addSeries("Decoy hits", DecoyObs, 100); //histogramDataset.addSeries("Model hits", ModelObs, 100); JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits", histogramDataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = chart.getXYPlot(); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(min, max); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setForegroundAlpha(0.8f); chart.setBackgroundPaint(Color.white); XYLineAndShapeRenderer render = new XYLineAndShapeRenderer(); plot.setDataset(1, dataset); plot.setRenderer(1, render); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); try { ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600); } catch (IOException e) { } }
/** * This method creates the JFreeChart based on all of the incoming data sets. * * @param eventsDataset This is the data set corresponding to the events bar chart graph. * @param recordersDataset This is the data set corresponding to the recorders line graph. * @param samplesDataset This is the data set corresponding to the samples line graph. * @return This returns a JFreeChart with all 3 of the graphs described. */ private static JFreeChart createChart(final CategoryDataset eventsDataset, final CategoryDataset recordersDataset, final CategoryDataset samplesDataset) { final CategoryItemRenderer eventsRenderer = new BarRenderer(); ((BarRenderer) eventsRenderer).setBarPainter(new StandardBarPainter()); // Remove shine ((BarRenderer) eventsRenderer).setShadowVisible(false); eventsRenderer.setSeriesPaint(0, new Color(224, 0, 51)); eventsRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); final CategoryPlot plot = new CategoryPlot(); plot.setDataset(eventsDataset); plot.setRenderer(eventsRenderer); plot.setDomainAxis(new CategoryAxis("")); plot.setRangeAxis(new NumberAxis("")); plot.setOrientation(PlotOrientation.VERTICAL); plot.setRangeGridlinesVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainAxis(new NumericCategoryAxis()); plot.getDomainAxis().setTickLabelFont(new Font("SansSerif", Font.PLAIN, 12)); final CategoryItemRenderer recorderRenderer = new LineAndShapeRenderer(true, false); recorderRenderer.setSeriesStroke(0, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 10.0f, 6.0f }, 0.0f)); recorderRenderer.setSeriesPaint(0, new Color(102, 102, 255)); recorderRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); // Temporarily removing recorders dataset // plot.setDataset(1, recordersDataset); // plot.setRenderer(1, recorderRenderer); final CategoryItemRenderer samplesRenderer = new LineAndShapeRenderer(true, false); samplesRenderer.setSeriesStroke(0, new BasicStroke(2.0f)); samplesRenderer.setSeriesPaint(0, new Color(0, 153, 0)); samplesRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setDataset(2, samplesDataset); plot.setRenderer(2, samplesRenderer); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_90); plot.getDomainAxis().setLowerMargin(0.025); plot.getDomainAxis().setUpperMargin(0.025); final JFreeChart chart = new JFreeChart(plot); return chart; }
/** * Creates a demo chart. * * @return A chart. */ @SuppressWarnings("deprecation") public static JFreeChart createChart(String title, double[] meanByWindow, int lengthOfWindow, int yearsPriorOfEvent, int yearsAfterEvent, double[][] leftEndPointSim, double[][] rightEndPointSim, String outputFilePrefix, int alphaLevel, int segmentIndex) { JSEABarChart.meanByWindow = meanByWindow; JSEABarChart.lengthOfWindow = lengthOfWindow; JSEABarChart.yearsPriorOfEvent = yearsPriorOfEvent; JSEABarChart.leftEndPointSim = leftEndPointSim; JSEABarChart.rightEndPointSim = rightEndPointSim; JSEABarChart.alphaLevel = alphaLevel; CategoryPlot plot = new CategoryPlot(); plot.setDataset(0, createDataset()); plot.setOrientation(PlotOrientation.VERTICAL); CustomBarRenderer renderer = new CustomBarRenderer(createPaint(lengthOfWindow, Color.gray)); renderer.setBarPainter(new StandardBarPainter()); renderer.setDrawBarOutline(false); renderer.setOutlinePaint(Color.yellow); renderer.setOutlineStroke(new BasicStroke(1.1f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL)); renderer.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL)); plot.setRenderer(0, renderer); Color allcolors[] = { Color.red, Color.green, Color.blue }; System.out.println("here is the alphlevel " + alphaLevel); // for (int k = 0; k <= 5; k++) { // if (k <= 2) { // / plot.setDataset(k + 1, createEndDataset(k, true)); // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k], k)); // } else { // plot.setDataset(k + 1, createEndDataset(k - 3, false)); // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k - 3], k - 3)); // } // } // for (int k = 0; k <1; k++) { // if (k <= 2) { plot.setDataset(1, createEndDataset(alphaLevel, true)); plot.setRenderer(1, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel)); // } else { plot.setDataset(4, createEndDataset(alphaLevel, false)); plot.setRenderer(4, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel)); // } // } plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // plot.setBackgroundPaint(Color.WHITE); plot.setDomainAxis(new CategoryAxis("LAG")); plot.addRangeMarker(new ValueMarker(0)); plot.setRangeAxis(new NumberAxis(outputFilePrefix)); plot.setRangeGridlinesVisible(true); JFreeChart chart = new JFreeChart(plot); chart.setTitle(title); chart.removeLegend(); chart.setBackgroundPaint(Color.WHITE); return chart; }
public AlignmentRansacPlot() { super(null, true); dataset = new XYSeriesCollection(); chart = ChartFactory.createXYLineChart("", null, null, dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); setChart(chart); // title chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); // legend constructed by ChartFactory legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setFrame(BlockBorder.NONE); // set the plot properties plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // set grid properties plot.setDomainGridlinePaint(gridColor); plot.setRangeGridlinePaint(gridColor); // set crosshair (selection) properties plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); plot.setDomainCrosshairPaint(crossHairColor); plot.setRangeCrosshairPaint(crossHairColor); plot.setDomainCrosshairStroke(crossHairStroke); plot.setRangeCrosshairStroke(crossHairStroke); // set default renderer properties XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setDefaultLinesVisible(false); renderer.setDefaultShapesVisible(true); renderer.setSeriesShape(0, dataPointsShape); renderer.setSeriesShape(1, dataPointsShape); renderer.setSeriesLinesVisible(2, true); renderer.setSeriesShapesVisible(2, false); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesPaint(1, Color.GRAY); renderer.setSeriesPaint(2, Color.BLUE); renderer.setDefaultItemLabelPaint(labelsColor); renderer.setDrawSeriesLineAsPath(true); plot.setRenderer(renderer); }
public HistogramChart() { super(null, true); // initialize the chart by default time series chart from factory chart = ChartFactory.createHistogram("", // title "", // x-axis label "", // y-axis label null, // data set PlotOrientation.VERTICAL, // orientation true, // create legend false, // generate tooltips false // generate URLs ); // title chartTitle = chart.getTitle(); chartTitle.setFont(titleFont); chartTitle.setMargin(5, 0, 0, 0); chartSubTitle = new TextTitle(); chartSubTitle.setFont(subTitleFont); chartSubTitle.setMargin(5, 0, 0, 0); chart.addSubtitle(chartSubTitle); // legend constructed by ChartFactory LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setFrame(BlockBorder.NONE); chart.setBackgroundPaint(Color.white); setChart(chart); // disable maximum size (we don't want scaling) setMaximumDrawWidth(Integer.MAX_VALUE); setMaximumDrawHeight(Integer.MAX_VALUE); // set the plot properties plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE); plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD); // set grid properties plot.setDomainGridlinePaint(gridColor); plot.setRangeGridlinePaint(gridColor); // set crosshair (selection) properties plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(true); // set the logarithmic axis NumberAxis axisDomain = new HistogramDomainAxis(); axisDomain.setMinorTickCount(1); axisDomain.setAutoRange(true); NumberAxis axisRange = new NumberAxis(); axisRange.setMinorTickCount(1); axisRange.setAutoRange(true); plot.setDomainAxis(axisDomain); plot.setRangeAxis(axisRange); ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer(); renderer.setMargin(marginSize); renderer.setShadowVisible(false); plot.setRenderer(renderer); this.setMinimumSize(new Dimension(400, 400)); this.setDismissDelay(Integer.MAX_VALUE); this.setInitialDelay(0); }
private JFreeChart getIecChart(ThemeDisplay themeDisplay) throws SystemException { final CategoryDataset porcentajeModulos = getDataSetPercentajes(themeDisplay); String chartTitle = LanguageUtil.get(themeDisplay.getLocale(), "userprogress.export.pdf.title"); String chartLabelLegend = LanguageUtil.get(themeDisplay.getLocale(), "userprogress.export.pdf.chart.legend.label"); String chartLabellLeft = LanguageUtil.get(themeDisplay.getLocale(), "userprogress.export.pdf.chart.label.left"); final JFreeChart chart = ChartFactory.createBarChart( chartTitle, // title chartLabelLegend, // domain axis label chartLabellLeft, // range axis label porcentajeModulos, // data PlotOrientation.VERTICAL, true, // legend true, // tooltips false // url ); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(new Color(222,222,222)); plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); plot.getRangeAxis(0).setRange(0, 100); final CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); plot.getRenderer().setSeriesPaint(0, gradientGray); final CategoryDataset horasRestantes = getDataSetTimeLeft(themeDisplay); plot.setDataset(1, horasRestantes); plot.mapDatasetToRangeAxis(1, 1); final ValueAxis axis2 = new NumberAxis(LanguageUtil.get(themeDisplay.getLocale(), "userprogress.export.pdf.chart.label.right")); plot.setRangeAxis(1, axis2); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setBaseLinesVisible(false); renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); plot.setRenderer(1, renderer2); plot.getRenderer(1).setSeriesPaint(0, gradientBlue); // Mostrar el primer dataset por debajo del resto de dataset plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); return chart; }
public void initialize() { final JFreeChart chart = chartNode.getChart(); final XYPlot plot = chart.getXYPlot(); // Do not set colors and strokes dynamically. They are instead provided // by the dataset and configured in configureRenderer() plot.setDrawingSupplier(null); plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); // chart properties chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); // legend properties LegendTitle legend = chart.getLegend(); // legend.setItemFont(legendFont); legend.setFrame(BlockBorder.NONE); // set the X axis (m/z) properties NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setLabel("m/z"); xAxis.setUpperMargin(0.03); xAxis.setLowerMargin(0.03); xAxis.setRangeType(RangeType.POSITIVE); xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20)); // set the Y axis (intensity) properties NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel("Intensity"); yAxis.setRangeType(RangeType.POSITIVE); yAxis.setAutoRangeIncludesZero(true); // set the fixed number formats, because otherwise JFreeChart sometimes // shows exponent, sometimes it doesn't DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); xAxis.setNumberFormatOverride(mzFormat); DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); yAxis.setNumberFormatOverride(intensityFormat); chartTitle = chartNode.getChart().getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); chartNode.setCursor(Cursor.CROSSHAIR); // Remove the dataset if it is removed from the list datasets.addListener((Change<? extends MsSpectrumDataSet> c) -> { while (c.next()) { if (c.wasRemoved()) { for (MsSpectrumDataSet ds : c.getRemoved()) { int index = plot.indexOf(ds); plot.setDataset(index, null); } } } }); itemLabelsVisible.addListener((prop, oldVal, newVal) -> { for (MsSpectrumDataSet dataset : datasets) { int datasetIndex = plot.indexOf(dataset); XYItemRenderer renderer = plot.getRenderer(datasetIndex); renderer.setBaseItemLabelsVisible(newVal); } }); legendVisible.addListener((prop, oldVal, newVal) -> { legend.setVisible(newVal); }); }
@FXML public void initialize() { final JFreeChart chart = chartNode.getChart(); final XYPlot plot = chart.getXYPlot(); // Do not set colors and strokes dynamically. They are instead provided // by the dataset and configured in configureRenderer() plot.setDrawingSupplier(null); plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor)); plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setDomainCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor)); plot.setRangeCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // chart properties chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor)); // legend properties LegendTitle legend = chart.getLegend(); // legend.setItemFont(legendFont); legend.setFrame(BlockBorder.NONE); // set the X axis (retention time) properties NumberAxis xAxis = (NumberAxis) plot.getDomainAxis(); xAxis.setLabel("Retention time (min)"); xAxis.setUpperMargin(0.03); xAxis.setLowerMargin(0.03); xAxis.setRangeType(RangeType.POSITIVE); xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20)); // set the Y axis (intensity) properties NumberAxis yAxis = (NumberAxis) plot.getRangeAxis(); yAxis.setLabel("Intensity"); yAxis.setRangeType(RangeType.POSITIVE); yAxis.setAutoRangeIncludesZero(true); // set the fixed number formats, because otherwise JFreeChart sometimes // shows exponent, sometimes it doesn't DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); xAxis.setNumberFormatOverride(mzFormat); DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); yAxis.setNumberFormatOverride(intensityFormat); chartTitle = chartNode.getChart().getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); chartTitle.setText("Chromatogram"); chartNode.setCursor(Cursor.CROSSHAIR); // Remove the dataset if it is removed from the list datasets.addListener((Change<? extends ChromatogramPlotDataSet> c) -> { while (c.next()) { if (c.wasRemoved()) { for (ChromatogramPlotDataSet ds : c.getRemoved()) { int index = plot.indexOf(ds); plot.setDataset(index, null); } } } }); itemLabelsVisible.addListener((prop, oldVal, newVal) -> { for (ChromatogramPlotDataSet dataset : datasets) { int datasetIndex = plot.indexOf(dataset); XYItemRenderer renderer = plot.getRenderer(datasetIndex); renderer.setBaseItemLabelsVisible(newVal); } }); legendVisible.addListener((prop, oldVal, newVal) -> { legend.setVisible(newVal); }); }
public void plot (Point upperLeft) { // All values, quorum line & spread line plotValues(); plotQuorumLine(); plotSpreadLine("", peak); // Second peak spread line? if (secondPeak != null) { plotSpreadLine("Second", secondPeak); } // Chart // JFreeChart chartLines = ChartFactory.createXYLineChart( // sheet.getId() + " (" + name + " runs)", // Title // "Lengths " + ((scale != null) ? scale : "*no scale*"), // X-Axis label // "Counts", // Y-Axis label // dataset, // Dataset // PlotOrientation.VERTICAL, // orientation, // true, // Show legend // false, // Show tool tips // false // urls // ); // use a histogram so we can see the actual buckets values // rather than being left to interpolate for any given length JFreeChart chart = ChartFactory.createHistogram( sheet.getId() + " (" + name + " runs)", // Title "", // X-Axis label - already labeled in chartLines "", // Y-Axis label - already labeled in chartLines dataset, // Dataset PlotOrientation.VERTICAL, // orientation, true, // Show legend false, // Show tool tips false // urls ); // have the quorum and spread be lines rather than bars XYPlot xyPlot = (XYPlot) chart.getPlot(); xyPlot.setDataset(1, datasetLines); XYLineAndShapeRenderer renderer1 = new XYLineAndShapeRenderer(); renderer1.setSeriesPaint(0, Color.GREEN); xyPlot.setRenderer(1, renderer1); // "FORWARD" causes the added dataset of // lines to be overlayed on histogram bars xyPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); // Hosting frame ChartFrame frame = new ChartFrame( sheet.getId() + " - " + name + " runs", chart, true); frame.pack(); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setLocation(upperLeft); frame.setVisible(true); }
ScatterPlotPanel(TopComponent parentDialog, String helpId) { super(parentDialog, helpId, CHART_TITLE, false); userSettingsMap = new HashMap<>(); productRemovedListener = new ProductManager.Listener() { @Override public void productAdded(ProductManager.Event event) { } @Override public void productRemoved(ProductManager.Event event) { final UserSettings userSettings = userSettingsMap.remove(event.getProduct()); if (userSettings != null) { userSettings.dispose(); } } }; xAxisRangeControl = new AxisRangeControl("X-Axis"); yAxisRangeControl = new AxisRangeControl("Y-Axis"); scatterPlotModel = new ScatterPlotModel(); bindingContext = new BindingContext(PropertyContainer.createObjectBacked(scatterPlotModel)); scatterpointsDataset = new XYIntervalSeriesCollection(); acceptableDeviationDataset = new XYIntervalSeriesCollection(); regressionDataset = new XYIntervalSeriesCollection(); r2Annotation = new XYTitleAnnotation(0, 0, new TextTitle("")); chart = ChartFactory.createScatterPlot(CHART_TITLE, "", "", scatterpointsDataset, PlotOrientation.VERTICAL, true, true, false); chart.getXYPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); createDomainAxisChangeListener(); final PropertyChangeListener userSettingsUpdateListener = evt -> { if (getRaster() != null) { final VectorDataNode pointDataSourceValue = scatterPlotModel.pointDataSource; final AttributeDescriptor dataFieldValue = scatterPlotModel.dataField; final UserSettings userSettings = getUserSettings(getRaster().getProduct()); userSettings.set(getRaster().getName(), pointDataSourceValue, dataFieldValue); } }; bindingContext.addPropertyChangeListener(PROPERTY_NAME_DATA_FIELD, userSettingsUpdateListener); bindingContext.addPropertyChangeListener(PROPERTY_NAME_POINT_DATA_SOURCE, userSettingsUpdateListener); }
private JFreeChart createHistogramChart() { XYBarRenderer renderer1 = new XYBarRenderer(); renderer1.setSeriesPaint(0, Color.cyan); renderer1.setSeriesPaint(1, Color.pink); XYPlot histPlot = new XYPlot(histogramDataset, null, new NumberAxis("count"), renderer1); XYBarRenderer renderer2 = new XYBarRenderer(); renderer2.setSeriesPaint(0, Color.green); renderer2.setSeriesPaint(1, Color.orange); renderer2.setUseYInterval(true); // weight and potential if (infoParser.isRobustBoost || infoParser.isAdaBoost || infoParser.isLogLossBoost) { StandardXYItemRenderer renderer3 = new StandardXYItemRenderer(); renderer3.setSeriesPaint(0, Color.blue); renderer3.setSeriesPaint(1, Color.red); renderer3.setBaseStroke(new BasicStroke(2)); StandardXYItemRenderer renderer4 = new StandardXYItemRenderer(); renderer4.setSeriesPaint(0, Color.blue); renderer4.setSeriesPaint(1, Color.red); renderer4.setBaseStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2, new float[] { 2 }, 0)); histPlot.setDataset(1, weightDataset); histPlot.setRenderer(1, renderer3); histPlot.setDataset(2, potentialDataset); histPlot.setRenderer(2, renderer4); histPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); } XYPlot fluctPlot = new XYPlot(fluctDataset, null, new NumberAxis("bin"), renderer2); double initialLocation = (upper_limit + lower_limit) / 2.0; histMarker = new IntervalMarker(initialLocation, initialLocation); histPlot.addDomainMarker(histMarker, Layer.BACKGROUND); fluctPlot.addDomainMarker(histMarker, Layer.BACKGROUND); // plot.setBackgroundPaint(Color.lightGray); // plot.setDomainGridlinePaint(Color.white); // plot.setRangeGridlinePaint(Color.white); CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(new NumberAxis("score")); combinedPlot.setGap(10.0); // add the subplots... ValueAxis axis = new NumberAxis(); axis.setRange(rawData.getMinRange(iter), rawData.getMaxRange(iter)); combinedPlot.add(histPlot, 3); combinedPlot.add(fluctPlot, 1); combinedPlot.setOrientation(PlotOrientation.VERTICAL); combinedPlot.setDomainAxis(axis); JFreeChart chart = new JFreeChart("Histogram", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, false // legend ); return chart; }
private JFreeChart createChart() { if (data.getItemCount() > 0) { // get cumulative percentages KeyedValues cumulative = DataUtilities.getCumulativePercentages(data); CategoryDataset categoryDataset = DatasetUtilities.createCategoryDataset("Count for " + this.dataTable.getColumnName(this.countColumn) + " = " + countValue, data); // create the chart... final JFreeChart chart = ChartFactory.createBarChart(null, // chart title this.dataTable.getColumnName(this.groupByColumn), // domain axis label "Count", // range axis label categoryDataset, // data PlotOrientation.VERTICAL, true, // include legend true, false); // set the background color for the chart... chart.setBackgroundPaint(Color.WHITE); // get a reference to the plot for further customization... CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setLowerMargin(0.02); domainAxis.setUpperMargin(0.02); domainAxis.setLabelFont(LABEL_FONT_BOLD); domainAxis.setTickLabelFont(LABEL_FONT); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits(Locale.US)); rangeAxis.setLabelFont(LABEL_FONT_BOLD); rangeAxis.setTickLabelFont(LABEL_FONT); // second data set (cumulative percentages) CategoryDataset dataset2 = DatasetUtilities.createCategoryDataset("Cumulative (Percent)", cumulative); LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); renderer2.setSeriesPaint(0, SwingTools.VERY_DARK_BLUE.darker()); NumberAxis axis2 = new NumberAxis("Percent of " + countValue); axis2.setNumberFormatOverride(NumberFormat.getPercentInstance()); axis2.setLabelFont(LABEL_FONT_BOLD); axis2.setTickLabelFont(LABEL_FONT); plot.setRangeAxis(1, axis2); plot.setDataset(1, dataset2); plot.setRenderer(1, renderer2); plot.mapDatasetToRangeAxis(1, 1); axis2.setTickUnit(new NumberTickUnit(0.1)); // show grid lines plot.setRangeGridlinesVisible(true); // bring cumulative line to front plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); if (isLabelRotating()) { domainAxis.setTickLabelsVisible(true); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0d)); } return chart; } else { return null; } }
private JFreeChart addLineChartOverBar(JFreeChart jfreechart, Object[] lineCharts, String lineLegend) throws QueryException { // first we read data for bar series, so we have to go back at the start of the result set try { result.getResultSet().beforeFirst(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } isLineCombo = true; lineBarDataset = new DefaultCategoryDataset(); boolean hasLegend = false; for (int i = 0; i < lineCharts.length; i++) { String legend = ""; try { legend = replaceParameters(lineLegend); } catch (IndexOutOfBoundsException ex){ // no legend set } if ((legend != null) && !"".equals(legend.trim())) { hasLegend = true; } lineCharts[i] = legend; } int index = chart.getYColumns().size()-1; CategoryPlot plot = jfreechart.getCategoryPlot(); final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer(); plot.setRenderer(1, renderer2); renderer2.setSeriesPaint(0, chart.getForegrounds().get(index)); final ValueAxis axis2 = new NumberAxis(""); plot.setRangeAxis(1, axis2); plot.setDataset(1, lineBarDataset); plot.mapDatasetToRangeAxis(1, 1); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); boolean showValues = (chart.getShowYValuesOnChart() == null) ? false : chart.getShowYValuesOnChart(); DecimalFormat decimalFormat; DecimalFormat percentageFormat; if (chart.getYTooltipPattern() == null) { decimalFormat = new DecimalFormat("#"); percentageFormat = new DecimalFormat("0.00%"); } else { decimalFormat = new DecimalFormat(chart.getYTooltipPattern()); percentageFormat = decimalFormat; } if (showValues) { renderer2.setSeriesItemLabelsVisible(0, true); renderer2.setSeriesItemLabelGenerator(0, new StandardCategoryItemLabelGenerator("{2}", decimalFormat, percentageFormat)); // increase a little bit the range axis to view all item label values over points plot.getRangeAxis(1).setUpperMargin(0.2); } final HashMap<String, String> formatValues = createChart(chart.getYColumns().subList(index, index+1), plot.getRangeAxis(1), lineCharts); isLineCombo = false; return jfreechart; }