List of usage examples for org.jfree.chart.plot XYPlot getDatasetCount
public int getDatasetCount()
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
@Override protected void clearDataSet(final IScope scope) { // TODO Auto-generated method stub super.clearDataSet(scope); final XYPlot plot = (XYPlot) this.chart.getPlot(); for (int i = plot.getDatasetCount() - 1; i >= 1; i--) { plot.setDataset(i, null);//from w w w . ja v a 2 s. c om plot.setRenderer(i, null); } ((MatrixSeriesCollection) jfreedataset.get(0)).removeAllSeries(); jfreedataset.clear(); jfreedataset.add(0, new MatrixSeriesCollection()); plot.setDataset((MatrixSeriesCollection) jfreedataset.get(0)); plot.setRenderer(0, null); IdPosition.clear(); }
From source file:ch.agent.crnickl.demo.stox.Chart.java
private void makeSubPlot(CombinedDomainXYPlot container, ChartSeries series) throws KeyedException { int index = series.getSubPlotIndex(); int nextDatasetOffset = 0; XYPlot plot = null; try {/*www. ja v a 2 s . c om*/ if (index > 0) { plot = (XYPlot) container.getSubplots().get(index - 1); nextDatasetOffset = plot.getDatasetCount(); } } catch (Exception e) { throw K.CHART_SUBPLOT_ERR.exception(e, index); } if (plot == null) plot = series.isLine() ? getLinePlot() : getBarPlot(); XYItemRenderer renderer = series.isLine() ? getLineRenderer() : getBarRenderer(); plot.setRenderer(nextDatasetOffset, renderer); plot.setDataset(nextDatasetOffset, getDataset(series.getTimeSeries(), series.getName())); if (index < 1) container.add(plot, series.getWeight()); }
From source file:de.uka.aifb.com.systemDynamics.gui.ModelExecutionChartPanel.java
/** * Creates panel./*from ww w . java 2s .com*/ */ private void createPanel() { setLayout(new BorderLayout()); // CENTER: chart ChartPanel chartPanel = new ChartPanel(createChart()); // no context menu chartPanel.setPopupMenu(null); // not zoomable chartPanel.setMouseZoomable(false); add(chartPanel, BorderLayout.CENTER); // LINE_END: series table JPanel tablePanel = new JPanel(new GridBagLayout()); String[] columnNames = { messages.getString("ModelExecutionChartPanel.Table.ColumnNames.ExtraAxis"), messages.getString("ModelExecutionChartPanel.Table.ColumnNames.LevelNode") }; final MyTableModel tableModel = new MyTableModel(columnNames, xySeriesArray.length); for (int i = 0; i < xySeriesArray.length; i++) { tableModel.addEntry((String) xySeriesArray[i].getKey()); } JTable table = new JTable(tableModel); table.setRowSelectionAllowed(false); JScrollPane tableScrollPane = new JScrollPane(table); int width = (int) Math.min(300, table.getPreferredSize().getWidth()); int height = (int) Math.min(200, table.getPreferredSize().getHeight()); tableScrollPane.getViewport().setPreferredSize(new Dimension(width, height)); tableScrollPane.setMaximumSize(tableScrollPane.getViewport().getPreferredSize()); axesButton = new JButton(messages.getString("ModelExecutionChartPanel.AxesButton.Text")); axesButton.setToolTipText(messages.getString("ModelExecutionChartPanel.AxesButton.ToolTipText")); axesButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // create XYSeriesCollections (and renderer) XYSeriesCollection standardData = new XYSeriesCollection(); XYLineAndShapeRenderer standardRenderer = new XYLineAndShapeRenderer(true, false); LinkedList<XYSeriesCollection> extraDataList = new LinkedList<XYSeriesCollection>(); LinkedList<XYLineAndShapeRenderer> extraRendererList = new LinkedList<XYLineAndShapeRenderer>(); for (int i = 0; i < tableModel.getRowCount(); i++) { if (tableModel.getValueAt(i, 0).equals(Boolean.FALSE)) { standardData.addSeries(xySeriesArray[i]); standardRenderer.setSeriesPaint(standardData.getSeriesCount() - 1, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]); } else { // extra axis XYSeriesCollection extraData = new XYSeriesCollection(); extraData.addSeries(xySeriesArray[i]); extraDataList.add(extraData); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false); extraRendererList.add(renderer); renderer.setSeriesPaint(0, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]); } } LinkedList<XYSeriesCollection> dataList = new LinkedList<XYSeriesCollection>(); LinkedList<XYLineAndShapeRenderer> rendererList = new LinkedList<XYLineAndShapeRenderer>(); if (!standardData.getSeries().isEmpty()) { dataList.add(standardData); rendererList.add(standardRenderer); } for (XYSeriesCollection data : extraDataList) { dataList.add(data); } for (XYLineAndShapeRenderer renderer : extraRendererList) { rendererList.add(renderer); } // creates axes LinkedList<NumberAxis> axesList = new LinkedList<NumberAxis>(); if (!standardData.getSeries().isEmpty()) { NumberAxis axis = new NumberAxis(messages.getString("ModelExecutionChartPanel.Value")); axis.setNumberFormatOverride(NumberFormat.getInstance(locale)); axesList.add(axis); } for (XYSeriesCollection data : extraDataList) { NumberAxis axis = new NumberAxis((String) data.getSeries(0).getKey()); axis.setNumberFormatOverride(NumberFormat.getInstance(locale)); axesList.add(axis); } // store data and axes in plot XYPlot plot = chart.getXYPlot(); plot.clearRangeAxes(); plot.setRangeAxes(axesList.toArray(new NumberAxis[0])); for (int i = 0; i < plot.getDatasetCount(); i++) { plot.setDataset(i, null); } int datasetIndex = 0; Iterator<XYSeriesCollection> datasetIterator = dataList.iterator(); Iterator<XYLineAndShapeRenderer> rendererIterator = rendererList.iterator(); while (datasetIterator.hasNext()) { plot.setDataset(datasetIndex, datasetIterator.next()); plot.setRenderer(datasetIndex, rendererIterator.next()); datasetIndex++; } for (int i = 0; i < plot.getDatasetCount(); i++) { plot.mapDatasetToRangeAxis(i, i); } } }); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.CENTER; c.gridx = 0; c.gridy = 0; c.insets = new Insets(0, 0, 10, 0); tablePanel.add(tableScrollPane, c); c.gridx = 0; c.gridy = 1; tablePanel.add(axesButton, c); add(tablePanel, BorderLayout.LINE_END); // PAGE_END: number of rounds and execution button JPanel commandPanel = new JPanel(); commandPanel.add(new JLabel(messages.getString("ModelExecutionChartPanel.NumberRounds"))); final JTextField numberRoundsField = new JTextField("1", 5); numberRoundsField.addFocusListener(this); commandPanel.add(numberRoundsField); executionButton = new JButton(messages.getString("ModelExecutionChartPanel.ExecutionButton.Text")); executionButton.setToolTipText(messages.getString("ModelExecutionChartPanel.ExecutionButton.ToolTipText")); executionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int numberRounds = 0; boolean correctNumber = false; try { numberRounds = integerNumberFormatter.parse(numberRoundsField.getText()).intValue(); } catch (ParseException parseExcep) { // do nothing } if (numberRounds >= 1) { correctNumber = true; } if (correctNumber) { ModelExecutionThread executionThread = new ModelExecutionThread(numberRounds); executionThread.start(); } else { JOptionPane.showMessageDialog(null, messages.getString("ModelExecutionChartPanel.Error.Message"), messages.getString("ModelExecutionChartPanel.Error.Title"), JOptionPane.ERROR_MESSAGE); } } }); commandPanel.add(executionButton); add(commandPanel, BorderLayout.PAGE_END); }
From source file:daylightchart.sunchart.chart.SunChart.java
/** * Creates bands for the sunrise and sunset times for the whole year. *///from w w w . j ava2 s . c om private void createBandsInPlot(final XYPlot plot) { final VectorSeriesCollection vectorSeriesCollection = new VectorSeriesCollection(); final List<SunPositions> sunPositionsList = sunChartData.getSunPositionsList(); for (final SunPositions sunPositions : sunPositionsList) { final VectorSeries vectorSeries = new VectorSeries(sunPositions.getDate().toString()); for (final SunPosition sunPosition : sunPositions) { vectorSeries.add(sunPosition.getAzimuth(), sunPosition.getAltitude(), 0, 0); } vectorSeriesCollection.addSeries(vectorSeries); } final int currentDatasetNumber = plot.getDatasetCount(); plot.setDataset(currentDatasetNumber, vectorSeriesCollection); }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputScatter.java
@Override protected void clearDataSet(final IScope scope) { // TODO Auto-generated method stub super.clearDataSet(scope); final XYPlot plot = (XYPlot) this.chart.getPlot(); for (int i = plot.getDatasetCount() - 1; i >= 1; i--) { plot.setDataset(i, null);/* w w w . j a v a 2s .c o m*/ plot.setRenderer(i, null); } ((XYIntervalSeriesCollection) jfreedataset.get(0)).removeAllSeries(); jfreedataset.clear(); jfreedataset.add(0, new XYIntervalSeriesCollection()); plot.setDataset((XYIntervalSeriesCollection) jfreedataset.get(0)); plot.setRenderer(0, null); IdPosition.clear(); }
From source file:io.github.mzmine.util.jfreechart.IntelligentItemLabelGenerator.java
/** * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset, * int, int)//from w w w .ja v a 2s.c om */ public String generateLabel(XYDataset currentDataset, int currentSeries, int currentItem) { XYPlot plot = chartNode.getChart().getXYPlot(); // X and Y values of the current data point final double currentXValue = currentDataset.getXValue(currentSeries, currentItem); final double currentYValue = currentDataset.getYValue(currentSeries, currentItem); // Calculate X axis span of 1 screen pixel final double xLength = plot.getDomainAxis().getRange().getLength(); final double pixelX = xLength / chartNode.getWidth(); // Calculate the distance from the current point where labels might // overlap final double dangerZoneX = (reservedPixels / 2) * pixelX; // Range on X axis that we're going to check for higher data points. If // a higher data point is found, we don't place a label on this one. final Range<Double> dangerZoneRange = Range.closed(currentXValue - dangerZoneX, currentXValue + dangerZoneX); // Iterate through data sets for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) { XYDataset dataset = plot.getDataset(datasetIndex); // Some data sets could have been removed if (dataset == null) continue; final int seriesCount = dataset.getSeriesCount(); // Iterate through series for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) { final int itemCount = dataset.getItemCount(seriesIndex); // Find the index of a data point that is closest to // currentXValue int closestValueIndex; if (dataset == currentDataset && seriesIndex == currentSeries) { closestValueIndex = currentItem; } else { closestValueIndex = findClosestXIndex(dataset, seriesIndex, currentXValue, 0, itemCount - 1); } // Search to the left of the closest data point for (int i = closestValueIndex; (i >= 0) && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i--) { if (dataset.getYValue(seriesIndex, i) > currentYValue) return null; // In the case there are equal values, only place the label // on the leftmost value if (dataset.getYValue(seriesIndex, i) == currentYValue && (dataset.getXValue(seriesIndex, i) < currentXValue)) return null; } // Search to the right of the closest data point for (int i = closestValueIndex + 1; (i < itemCount) && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i++) { if (dataset.getYValue(seriesIndex, i) > currentYValue) return null; } } } // If no higher data point was found, create the label String label = underlyingGenerator.generateLabel(currentDataset, currentSeries, currentItem); return label; }
From source file:net.sf.mzmine.chartbasics.HistogramChartFactory.java
/** * Adds a Gaussian curve to the plot//from w ww .java 2 s.co m * * @param plot * @param fit double[] {normFactor, mean, sigma} * @param drawStart start of curve * @param drawEnd end of curve * @param gMin lower bound of Gaussian fit * @param gMax upper bound of Gaussian fit * @param sigDigits number of significant digits * @return */ public static double[] addGaussianFit(XYPlot plot, double[] fit, double drawStart, double drawEnd, double gMin, double gMax, int sigDigits, boolean annotations) { double gWidth = gMax - gMin; Gaussian g = new Gaussian(fit[0], fit[1], fit[2]); // create xy series for gaussian String mean = Precision.toString(fit[1], sigDigits, 7); String sigma = Precision.toString(fit[2], sigDigits, 7); String norm = Precision.toString(fit[0], sigDigits, 7); XYSeries gs = new XYSeries( "Gaussian: " + mean + " \u00B1 " + sigma + " [" + norm + "] (mean \u00B1 sigma [normalisation])"); // add lower dp number out of gaussian fit range int steps = 100; if (gMin > drawStart) { for (int i = 0; i <= steps; i++) { double x = drawStart + ((gMin - drawStart) / steps) * i; double y = g.value(x); gs.add(x, y); } } // add high resolution in gaussian fit area steps = 1000; for (int i = 0; i <= steps; i++) { double x = gMin + (gWidth / steps) * i; double y = g.value(x); gs.add(x, y); } // add lower dp number out of gaussian fit range steps = 100; if (gMax < drawEnd) { for (int i = 0; i <= steps; i++) { double x = gMax + ((drawEnd - gMax) / steps) * i; double y = g.value(x); gs.add(x, y); } } // add gaussian XYSeriesCollection gsdata = new XYSeriesCollection(gs); int index = plot.getDatasetCount(); plot.setDataset(index, gsdata); plot.setRenderer(index, new XYLineAndShapeRenderer(true, false)); if (annotations) addGaussianFitAnnotations(plot, fit); return fit; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * init plot/*from w ww . ja va 2 s . c o m*/ * * @param plot plot */ protected void initPlot(Plot plot) { XYPlot xyPlot = (XYPlot) plot; int count = xyPlot.getDatasetCount(); for (int i = 0; i < count; i++) { xyPlot.setDataset(i, null); xyPlot.setRenderer(i, null); } xyPlot.clearRangeAxes(); XYDataset dummyDataset = getDummyDataset(); ValueAxis rangeAxis = new FixedWidthNumberAxis(); xyPlot.setRangeAxis(0, rangeAxis, false); xyPlot.setDataset(0, dummyDataset); xyPlot.mapDatasetToRangeAxis(0, 0); xyPlot.setRenderer(0, new XYLineAndShapeRenderer()); }
From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java
private void initXYPlot(JFreeChart chart, ChartModel chartModel) { initPlot(chart, chartModel);//from w ww. ja v a 2 s .com org.pentaho.chart.model.TwoAxisPlot twoAxisPlot = (org.pentaho.chart.model.TwoAxisPlot) chartModel .getPlot(); XYPlot xyPlot = chart.getXYPlot(); List<Integer> colors = getPlotColors(twoAxisPlot); for (int i = 0; i < colors.size(); i++) { for (int j = 0; j < xyPlot.getDatasetCount(); j++) { xyPlot.getRenderer(j).setSeriesPaint(i, new Color(0x00FFFFFF & colors.get(i))); } } Font domainAxisFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getFontFamily(), twoAxisPlot.getDomainAxis().getFontStyle(), twoAxisPlot.getDomainAxis().getFontWeight(), twoAxisPlot.getDomainAxis().getFontSize()); Font rangeAxisFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getFontFamily(), twoAxisPlot.getRangeAxis().getFontStyle(), twoAxisPlot.getRangeAxis().getFontWeight(), twoAxisPlot.getRangeAxis().getFontSize()); Font rangeTitleFont = ChartUtils.getFont(twoAxisPlot.getRangeAxis().getLegend().getFontFamily(), twoAxisPlot.getRangeAxis().getLegend().getFontStyle(), twoAxisPlot.getRangeAxis().getLegend().getFontWeight(), twoAxisPlot.getRangeAxis().getLegend().getFontSize()); Font domainTitleFont = ChartUtils.getFont(twoAxisPlot.getDomainAxis().getLegend().getFontFamily(), twoAxisPlot.getDomainAxis().getLegend().getFontStyle(), twoAxisPlot.getDomainAxis().getLegend().getFontWeight(), twoAxisPlot.getDomainAxis().getLegend().getFontSize()); NumberAxis domainAxis = (NumberAxis) xyPlot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) xyPlot.getRangeAxis(); domainAxis.setAutoRangeIncludesZero(true); rangeAxis.setAutoRangeIncludesZero(true); AxesLabels axesLabels = getAxesLabels(chartModel); if ((axesLabels.rangeAxisLabel.length() > 0) && (rangeTitleFont != null)) { rangeAxis.setLabelFont(rangeTitleFont); } if ((axesLabels.domainAxisLabel.length() > 0) && (domainTitleFont != null)) { domainAxis.setLabelFont(domainTitleFont); } domainAxis.setVerticalTickLabels( twoAxisPlot.getHorizontalAxis().getLabelOrientation() == LabelOrientation.VERTICAL); if (domainAxisFont != null) { domainAxis.setTickLabelFont(domainAxisFont); } if (rangeAxisFont != null) { rangeAxis.setTickLabelFont(rangeAxisFont); } Number rangeMin = ((NumericAxis) twoAxisPlot.getRangeAxis()).getMinValue(); if (rangeMin != null) { rangeAxis.setLowerBound(rangeMin.doubleValue()); } Number rangeMax = ((NumericAxis) twoAxisPlot.getRangeAxis()).getMaxValue(); if (rangeMax != null) { rangeAxis.setUpperBound(rangeMax.doubleValue()); } }
From source file:de.tor.tribes.ui.views.DSWorkbenchStatsFrame.java
private void addDataset(String pId, XYDataset pDataset) { if (chart == null) { setupChart(pId, pDataset);//w w w.ja v a 2 s .c o m } else { XYPlot plot = (XYPlot) chart.getPlot(); plot.setDataset(plot.getDatasetCount(), pDataset); NumberAxis axis = new NumberAxis(pId); NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(0); axis.setNumberFormatOverride(nf); plot.setRangeAxis(plot.getDatasetCount() - 1, axis); plot.setRangeAxisLocation(plot.getDatasetCount() - 1, AxisLocation.TOP_OR_LEFT); plot.mapDatasetToRangeAxis(plot.getDatasetCount() - 1, plot.getDatasetCount() - 1); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, jShowLines.isSelected()); renderer.setSeriesShapesVisible(0, jShowDataPoints.isSelected()); plot.setRenderer(plot.getDatasetCount() - 1, renderer); renderer.setDefaultItemLabelsVisible(jShowItemValues.isSelected()); renderer.setDefaultItemLabelGenerator(new org.jfree.chart.labels.StandardXYItemLabelGenerator()); renderer.setDefaultToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"), NumberFormat.getInstance())); axis.setAxisLinePaint(plot.getLegendItems().get(plot.getDatasetCount() - 1).getLinePaint()); axis.setLabelPaint(plot.getLegendItems().get(plot.getDatasetCount() - 1).getLinePaint()); axis.setTickLabelPaint(plot.getLegendItems().get(plot.getDatasetCount() - 1).getLinePaint()); axis.setTickMarkPaint(plot.getLegendItems().get(plot.getDatasetCount() - 1).getLinePaint()); } }