/** * Get the paint for a given series and item from a dataset. * * @param dataset the dataset.. * @param series the series index. * @param item the item index. * * @return The paint. */ protected Paint getPaint(XYDataset dataset, int series, int item) { Paint p; if (dataset instanceof XYZDataset) { double z = ((XYZDataset) dataset).getZValue(series, item); p = this.paintScale.getPaint(z); } else { if (this.useFillPaint) { p = getItemFillPaint(series, item); } else { p = getItemPaint(series, item); } } return p; }
/** * Iterates over the data items of the xyz dataset to find * the z-dimension bounds. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval include the z-interval (if the dataset has a * z-interval. * * @return The range (possibly <code>null</code>). */ public static Range iterateZBounds(XYZDataset dataset, boolean includeInterval) { double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = dataset.getZValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
/** * Get the paint for a given series and item from a dataset. * * @param dataset the dataset. * @param series the series index. * @param item the item index. * * @return The paint. */ protected Paint getPaint(XYDataset dataset, int series, int item) { Paint p; if (dataset instanceof XYZDataset) { double z = ((XYZDataset) dataset).getZValue(series, item); p = this.paintScale.getPaint(z); } else { if (this.useFillPaint) { p = getItemFillPaint(series, item); } else { p = getItemPaint(series, item); } } return p; }
/** * Iterates over the data items of the xyz dataset to find * the z-dimension bounds. * * @param dataset the dataset ({@code null} not permitted). * @param includeInterval include the z-interval (if the dataset has a * z-interval. * * @return The range (possibly {@code null}). */ public static Range iterateZBounds(XYZDataset dataset, boolean includeInterval) { double minimum = Double.POSITIVE_INFINITY; double maximum = Double.NEGATIVE_INFINITY; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int itemCount = dataset.getItemCount(series); for (int item = 0; item < itemCount; item++) { double value = dataset.getZValue(series, item); if (!Double.isNaN(value)) { minimum = Math.min(minimum, value); maximum = Math.max(maximum, value); } } } if (minimum == Double.POSITIVE_INFINITY) { return null; } else { return new Range(minimum, maximum); } }
private XYZDataset createXyzDataset() { if (sampleXyzDataset == null) { DefaultXYZDataset dataset = new DefaultXYZDataset(); dataset.addSeries( "First", new double[][]{ {2.1, 2.3, 2.3, 2.2, 2.2, 1.8, 1.8, 1.9, 2.3, 3.8}, {14.1, 11.1, 10.0, 8.8, 8.7, 8.4, 5.4, 4.1, 4.1, 25}, {2.4, 2.7, 2.7, 2.2, 2.2, 2.2, 2.1, 2.2, 1.6, 4} } ); sampleXyzDataset = dataset; } return sampleXyzDataset; }
/** * create chart using data from the dataTable */ public void doChart(){ if(dataTable.isEditing()) dataTable.getCellEditor().stopCellEditing(); if (! hasExample ) { showMessageDialog(DATA_MISSING_MESSAGE); resetChart(); return; } isDemo = false; XYZDataset dataset = createDataset(isDemo); JFreeChart chart = createChart(dataset); chartPanel = new ChartPanel(chart, isDemo); setChart(); //updateStatus("Chart has been updated, click GRAPH to view it."); }
/** * Get the paint for a given series and item from a dataset. * * @param dataset the dataset.. * @param series the series index. * @param item the item index. * * @return The paint. */ protected Paint getPaint(XYDataset dataset, int series, int item) { Paint p = null; if (dataset instanceof XYZDataset) { double z = ((XYZDataset) dataset).getZValue(series, item); p = this.paintScale.getPaint(z); } else { if (this.useFillPaint) { p = getItemFillPaint(series, item); } else { p = getItemPaint(series, item); } } return p; }
/** * Creates a bubble chart with default settings. The chart is composed of * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} * to draw the data items. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param legend a flag specifying whether or not a legend is required. * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, boolean legend) { NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer( XYBubbleRenderer.SCALE_ON_RANGE_AXIS); renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); plot.setRenderer(renderer); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Get the paint for a given series and item from a dataset. * * @param dataset the dataset.. * @param series the series index. * @param item the item index. * @param selected is the data item selected? * * @return The paint. * * @since 1.2.0 */ protected Paint getPaint(XYDataset dataset, int series, int item, boolean selected) { Paint p = null; if (dataset instanceof XYZDataset) { double z = ((XYZDataset) dataset).getZValue(series, item); p = this.paintScale.getPaint(z); } else { if (this.useFillPaint) { p = getItemFillPaint(series, item, selected); } else { p = getItemPaint(series, item, selected); } } return p; }
/** * Creates a bubble chart with default settings. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) (<code>null</code> NOT * permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return a bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer(XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
/** * Creates the array of items that can be passed to the {@link MessageFormat} class * for creating labels. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The items (never <code>null</code>). */ protected Object[] createItemArray(XYZDataset dataset, int series, int item) { Object[] result = new Object[4]; result[0] = dataset.getSeriesName(series); Number x = dataset.getX(series, item); DateFormat xf = getXDateFormat(); if (xf != null) { result[1] = xf.format(x); } else { result[1] = getXFormat().format(x); } Number y = dataset.getY(series, item); DateFormat yf = getYDateFormat(); if (yf != null) { result[2] = yf.format(y); } else { result[2] = getYFormat().format(y); } Number z = dataset.getZ(series, item); if (this.zDateFormat != null) { result[3] = this.zDateFormat.format(z); } else { result[3] = this.zFormat.format(z); } return result; }
/** * Creates a bubble chart with default settings. The chart is composed of * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} * to draw the data items. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer( XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double z = 0.0; if (dataset instanceof XYZDataset) { z = ((XYZDataset) dataset).getZValue(series, item); } Paint p = this.paintScale.getPaint(z); double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea, plot.getRangeAxisEdge()); double xx1 = domainAxis.valueToJava2D(x + this.blockWidth + this.xOffset, dataArea, plot.getDomainAxisEdge()); double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight + this.yOffset, dataArea, plot.getRangeAxisEdge()); Rectangle2D block; PlotOrientation orientation = plot.getOrientation(); if (orientation.equals(PlotOrientation.HORIZONTAL)) { block = new Rectangle2D.Double(Math.min(yy0, yy1), Math.min(xx0, xx1), Math.abs(yy1 - yy0), Math.abs(xx0 - xx1)); } else { block = new Rectangle2D.Double(Math.min(xx0, xx1), Math.min(yy0, yy1), Math.abs(xx1 - xx0), Math.abs(yy1 - yy0)); } g2.setPaint(p); g2.fill(block); g2.setStroke(new BasicStroke(1.0f)); g2.draw(block); }
/** * Generates a label string for an item in the dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The label (possibly <code>null</code>). */ public String generateLabelString(XYDataset dataset, int series, int item) { String result = null; Object[] items = null; if (dataset instanceof XYZDataset) { items = createItemArray((XYZDataset) dataset, series, item); } else { items = createItemArray(dataset, series, item); } result = MessageFormat.format(getFormatString(), items); return result; }
/** * Creates the array of items that can be passed to the * {@link MessageFormat} class for creating labels. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The items (never <code>null</code>). */ protected Object[] createItemArray(XYZDataset dataset, int series, int item) { Object[] result = new Object[4]; result[0] = dataset.getSeriesKey(series).toString(); Number x = dataset.getX(series, item); DateFormat xf = getXDateFormat(); if (xf != null) { result[1] = xf.format(x); } else { result[1] = getXFormat().format(x); } Number y = dataset.getY(series, item); DateFormat yf = getYDateFormat(); if (yf != null) { result[2] = yf.format(y); } else { result[2] = getYFormat().format(y); } Number z = dataset.getZ(series, item); if (this.zDateFormat != null) { result[3] = this.zDateFormat.format(z); } else { result[3] = this.zFormat.format(z); } return result; }
/** * Creates a bubble chart with default settings. The chart is composed of * an {@link XYPlot}, with a {@link NumberAxis} for the domain axis, * a {@link NumberAxis} for the range axis, and an {@link XYBubbleRenderer} * to draw the data items. * * @param title the chart title (<code>null</code> permitted). * @param xAxisLabel a label for the X-axis (<code>null</code> permitted). * @param yAxisLabel a label for the Y-axis (<code>null</code> permitted). * @param dataset the dataset for the chart (<code>null</code> permitted). * @param orientation the orientation (horizontal or vertical) * (<code>null</code> NOT permitted). * @param legend a flag specifying whether or not a legend is required. * @param tooltips configure chart to generate tool tips? * @param urls configure chart to generate URLs? * * @return A bubble chart. */ public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) { ParamChecks.nullNotPermitted(orientation, "orientation"); NumberAxis xAxis = new NumberAxis(xAxisLabel); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(yAxisLabel); yAxis.setAutoRangeIncludesZero(false); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null); XYItemRenderer renderer = new XYBubbleRenderer( XYBubbleRenderer.SCALE_ON_RANGE_AXIS); if (tooltips) { renderer.setBaseToolTipGenerator(new StandardXYZToolTipGenerator()); } if (urls) { renderer.setURLGenerator(new StandardXYZURLGenerator()); } plot.setRenderer(renderer); plot.setOrientation(orientation); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); currentTheme.apply(chart); return chart; }
/** * Return the range of z-values in the specified dataset. * * @param dataset the dataset (<code>null</code> permitted). * * @return The range (<code>null</code> if the dataset is <code>null</code> * or empty). */ public Range findZBounds(XYZDataset dataset) { if (dataset != null) { return DatasetUtilities.findZBounds(dataset); } else { return null; } }
/** * Generates a label string for an item in the dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series (zero-based index). * @param item the item (zero-based index). * * @return The label (possibly <code>null</code>). */ @Override public String generateLabelString(XYDataset dataset, int series, int item) { String result; Object[] items; if (dataset instanceof XYZDataset) { items = createItemArray((XYZDataset) dataset, series, item); } else { items = createItemArray(dataset, series, item); } result = MessageFormat.format(getFormatString(), items); return result; }