org.jfree.data.xy.XYDataset Java Examples
The following examples show how to use
org.jfree.data.xy.XYDataset.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormulaXYZTooltipGenerator.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Generates the tooltip text for the specified item. * * @param dataset the dataset (<code>null</code> not permitted). * @param series the series index (zero-based). * @param item the item index (zero-based). * @return The tooltip text (possibly <code>null</code>). */ public String generateToolTip( final XYDataset dataset, final int series, final int item ) { if ( dataset instanceof XYZDataset ) { return generateToolTip( (XYZDataset) dataset, series, item ); } try { final Object[] values = new Object[] { dataset.getX( series, item ), dataset.getY( series, item ), null, IntegerCache.getInteger( series ), dataset.getSeriesKey( series ), IntegerCache.getInteger( dataset.getSeriesCount() ), IntegerCache.getInteger( item ), IntegerCache.getInteger( dataset.getItemCount( series ) ) }; formulaExpression.setRuntime( new WrapperExpressionRuntime ( new StaticDataRow( ADDITIONAL_COLUMN_KEYS, values ), runtime ) ); final Object o = formulaExpression.getValue(); if ( o == null ) { return null; } return String.valueOf( o ); } finally { formulaExpression.setRuntime( null ); } }
Example #2
Source File: XYPlotTest.java From openstock with GNU General Public License v3.0 | 6 votes |
@Test public void testAxisIndices() { XYDataset dataset = new XYSeriesCollection(); NumberAxis xAxis = new NumberAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); XYItemRenderer renderer = new DefaultXYItemRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); assertEquals(xAxis, plot.getDomainAxis(0)); assertEquals(yAxis, plot.getRangeAxis(0)); NumberAxis xAxis2 = new NumberAxis("X2"); plot.setDomainAxis(99, xAxis2); assertEquals(xAxis2, plot.getDomainAxis(99)); NumberAxis yAxis2 = new NumberAxis("Y2"); plot.setRangeAxis(99, yAxis2); assertEquals(yAxis2, plot.getRangeAxis(99)); }
Example #3
Source File: XYPlotTest.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Datasets are now stored in a Map, and it should be possible to assign * them an arbitrary key (index). */ @Test public void testDatasetIndices() { XYDataset dataset = new XYSeriesCollection(); NumberAxis xAxis = new NumberAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); XYItemRenderer renderer = new DefaultXYItemRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); assertEquals(dataset, plot.getDataset(0)); XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(new XYSeries("Series in dataset 2")); // we should be able to give a dataset an arbitrary index plot.setDataset(99, dataset2); assertEquals(2, plot.getDatasetCount()); assertEquals(dataset2, plot.getDataset(99)); assertEquals(0, plot.indexOf(dataset)); assertEquals(99, plot.indexOf(dataset2)); }
Example #4
Source File: XYPlotTest.java From openstock with GNU General Public License v3.0 | 6 votes |
@Test public void testGetRendererForDataset2() { XYDataset dataset = new XYSeriesCollection(); NumberAxis xAxis = new NumberAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); XYItemRenderer renderer = new DefaultXYItemRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); // add a second dataset XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(new XYSeries("Series in dataset 2")); plot.setDataset(99, dataset2); // by default, the renderer with index 0 is used assertEquals(renderer, plot.getRendererForDataset(dataset2)); // add a second renderer with the same index as dataset2, now it will // be used XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); plot.setRenderer(99, renderer); assertEquals(renderer2, plot.getRendererForDataset(dataset2)); }
Example #5
Source File: XYPlot.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * A utility method that returns a list of datasets that are mapped to a * particular axis. * * @param axisIndex the axis index (<code>null</code> not permitted). * * @return A list of datasets. */ private List<XYDataset> getDatasetsMappedToRangeAxis(Integer axisIndex) { ParamChecks.nullNotPermitted(axisIndex, "axisIndex"); List<XYDataset> result = new ArrayList<XYDataset>(); for (Entry<Integer, XYDataset> entry : this.datasets.entrySet()) { int index = entry.getKey(); List<Integer> mappedAxes = this.datasetToRangeAxesMap.get(index); if (mappedAxes == null) { if (axisIndex.equals(ZERO)) { result.add(entry.getValue()); } } else { if (mappedAxes.contains(axisIndex)) { result.add(entry.getValue()); } } } return result; }
Example #6
Source File: DistributionPlotter.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
private XYDataset createNumericalDataSet() { XYSeriesCollection dataSet = new XYSeriesCollection(); int translatedPlotColumn = translateToModelColumn(plotColumn); double start = model.getLowerBound(translatedPlotColumn); double end = model.getUpperBound(translatedPlotColumn); double stepSize = (end - start) / (NUMBER_OF_STEPS - 1); for (int classIndex : model.getClassIndices()) { XYSeries series = new XYSeries(model.getClassName(classIndex)); ContinuousDistribution distribution = (ContinuousDistribution) model.getDistribution(classIndex, translatedPlotColumn); for (double currentValue = start; currentValue < end; currentValue += stepSize) { double probability = distribution.getProbability(currentValue); if (!Double.isNaN(probability)) { series.add(currentValue, distribution.getProbability(currentValue)); } } dataSet.addSeries(series); } return dataSet; }
Example #7
Source File: JGenProg2017_0047_s.java From coming with MIT License | 6 votes |
/** * Returns the range of values in the domain (x-values) of a dataset. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval determines whether or not the x-interval is taken * into account (only applies if the dataset is an * {@link IntervalXYDataset}). * * @return The range of values (possibly <code>null</code>). */ public static Range findDomainBounds(XYDataset dataset, boolean includeInterval) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } Range result = null; // if the dataset implements DomainInfo, life is easier if (dataset instanceof DomainInfo) { DomainInfo info = (DomainInfo) dataset; result = info.getDomainBounds(includeInterval); } else { result = iterateDomainBounds(dataset, includeInterval); } return result; }
Example #8
Source File: XYBlockRenderer.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Returns the range of values the renderer requires to display all the * items from 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). * * @see #findDomainBounds(XYDataset) */ @Override public Range findRangeBounds(XYDataset dataset) { if (dataset != null) { Range r = DatasetUtilities.findRangeBounds(dataset, false); if (r == null) { return null; } else { return new Range(r.getLowerBound() + this.yOffset, r.getUpperBound() + this.blockHeight + this.yOffset); } } else { return null; } }
Example #9
Source File: StackedXYAreaRenderer2.java From opensim-gui with Apache License 2.0 | 6 votes |
/** * Returns the range of values the renderer requires to display all the * items from the specified dataset. * * @param dataset the dataset (<code>null</code> permitted). * * @return The range (or <code>null</code> if the dataset is * <code>null</code> or empty). */ public Range findRangeBounds(XYDataset dataset) { if (dataset == null) { return null; } double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; TableXYDataset d = (TableXYDataset) dataset; int itemCount = d.getItemCount(); for (int i = 0; i < itemCount; i++) { double[] stackValues = getStackValues((TableXYDataset) dataset, d.getSeriesCount(), i); min = Math.min(min, stackValues[0]); max = Math.max(max, stackValues[1]); } if (min == Double.POSITIVE_INFINITY) { return null; } return new Range(min, max); }
Example #10
Source File: AbstractXYItemRenderer.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Returns the lower and upper bounds (range) of the x-values in the * specified dataset. * * @param dataset the dataset (<code>null</code> permitted). * @param includeInterval include the interval (if any) for the dataset? * * @return The range (<code>null</code> if the dataset is <code>null</code> * or empty). * * @since 1.0.13 */ protected Range findDomainBounds(XYDataset dataset, boolean includeInterval) { if (dataset == null) { return null; } if (getDataBoundsIncludesVisibleSeriesOnly()) { List visibleSeriesKeys = new ArrayList(); int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { if (isSeriesVisible(s)) { visibleSeriesKeys.add(dataset.getSeriesKey(s)); } } return DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, includeInterval); } return DatasetUtilities.findDomainBounds(dataset, includeInterval); }
Example #11
Source File: TimeSeriesChartTest.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); }
Example #12
Source File: SwingCombinedChartGestureDemo.java From old-mzmine3 with GNU General Public License v2.0 | 6 votes |
private JFreeChart createCombinedChart() { // create subplot 1... final XYDataset data1 = createDataset(); final XYItemRenderer renderer1 = new StandardXYItemRenderer(); final NumberAxis rangeAxis1 = new NumberAxis("Range 1"); final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); // create subplot 2... final XYDataset data2 = createDataset(); final XYItemRenderer renderer2 = new StandardXYItemRenderer(); final NumberAxis rangeAxis2 = new NumberAxis("Range 2"); final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); // parent plot... final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); // return a new chart containing the overlaid plot... return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true); }
Example #13
Source File: XYPlotTest.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Datasets are now stored in a Map, and it should be possible to assign * them an arbitrary key (index). */ @Test public void testDatasetIndices() { XYDataset dataset = new XYSeriesCollection(); NumberAxis xAxis = new NumberAxis("X"); NumberAxis yAxis = new NumberAxis("Y"); XYItemRenderer renderer = new DefaultXYItemRenderer(); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); assertEquals(dataset, plot.getDataset(0)); XYSeriesCollection dataset2 = new XYSeriesCollection(); dataset2.addSeries(new XYSeries("Series in dataset 2")); // we should be able to give a dataset an arbitrary index plot.setDataset(99, dataset2); assertEquals(2, plot.getDatasetCount()); assertEquals(dataset2, plot.getDataset(99)); assertEquals(0, plot.indexOf(dataset)); assertEquals(99, plot.indexOf(dataset2)); }
Example #14
Source File: RegressionTest.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * Checks the results of an OLS regression on sample dataset 2 AFTER * converting it to an XYSeries. */ @Test public void testOLSRegression2b() { double[][] data = createSampleData2(); XYSeries series = new XYSeries("Test"); for (int i = 0; i < 10; i++) { series.add(data[i][0], data[i][1]); } XYDataset ds = new XYSeriesCollection(series); double[] result = Regression.getOLSRegression(ds, 0); assertEquals(53.9729697, result[0], 0.0000001); assertEquals(-4.1823030, result[1], 0.0000001); }
Example #15
Source File: XYStepAreaChartTest.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); }
Example #16
Source File: AbstractXYItemRenderer.java From opensim-gui with Apache License 2.0 | 6 votes |
/** * Adds an entity to the collection. * * @param entities the entity collection being populated. * @param area the entity area (if <code>null</code> a default will be * used). * @param dataset the dataset. * @param series the series. * @param item the item. * @param entityX the entity's center x-coordinate in user space. * @param entityY the entity's center y-coordinate in user space. */ protected void addEntity(EntityCollection entities, Shape area, XYDataset dataset, int series, int item, double entityX, double entityY) { if (!getItemCreateEntity(series, item)) { return; } if (area == null) { area = new Ellipse2D.Double(entityX - this.defaultEntityRadius, entityY - this.defaultEntityRadius, this.defaultEntityRadius * 2, this.defaultEntityRadius * 2); } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } XYItemEntity entity = new XYItemEntity(area, dataset, series, item, tip, url); entities.add(entity); }
Example #17
Source File: RegressionTest.java From buffer_bci with GNU General Public License v3.0 | 6 votes |
/** * Checks the results of an OLS regression on sample dataset 2 AFTER * converting it to an XYSeries. */ @Test public void testOLSRegression2b() { double[][] data = createSampleData2(); XYSeries series = new XYSeries("Test"); for (int i = 0; i < 10; i++) { series.add(data[i][0], data[i][1]); } XYDataset ds = new XYSeriesCollection(series); double[] result = Regression.getOLSRegression(ds, 0); assertEquals(53.9729697, result[0], 0.0000001); assertEquals(-4.1823030, result[1], 0.0000001); }
Example #18
Source File: BoxAndWhiskerXYToolTipGenerator.java From ECG-Viewer with GNU General Public License v2.0 | 6 votes |
/** * 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>). */ @Override protected Object[] createItemArray(XYDataset dataset, int series, int item) { Object[] result = new Object[8]; result[0] = dataset.getSeriesKey(series).toString(); Number x = dataset.getX(series, item); if (getXDateFormat() != null) { result[1] = getXDateFormat().format(new Date(x.longValue())); } else { result[1] = getXFormat().format(x); } NumberFormat formatter = getYFormat(); if (dataset instanceof BoxAndWhiskerXYDataset) { BoxAndWhiskerXYDataset d = (BoxAndWhiskerXYDataset) dataset; result[2] = formatter.format(d.getMeanValue(series, item)); result[3] = formatter.format(d.getMedianValue(series, item)); result[4] = formatter.format(d.getMinRegularValue(series, item)); result[5] = formatter.format(d.getMaxRegularValue(series, item)); result[6] = formatter.format(d.getQ1Value(series, item)); result[7] = formatter.format(d.getQ3Value(series, item)); } return result; }
Example #19
Source File: XYAreaChartExpression.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
protected JFreeChart computeXYChart( final XYDataset xyDataset ) { final JFreeChart chart; if ( xyDataset instanceof TimeSeriesCollection ) { if ( isStacked() ) { final ExtTimeTableXYDataset tableXYDataset = convertToTable( xyDataset ); chart = createTimeSeriesChart( computeTitle(), getDomainTitle(), getRangeTitle(), tableXYDataset, isShowLegend(), false, false, isStacked() ); } else { chart = createTimeSeriesChart( computeTitle(), getDomainTitle(), getRangeTitle(), xyDataset, isShowLegend(), false, false, isStacked() ); } } else { final PlotOrientation orientation = computePlotOrientation(); if ( isStacked() ) { chart = createStackedXYAreaChart( computeTitle(), getDomainTitle(), getRangeTitle(), xyDataset, orientation, isShowLegend(), false, false ); } else { chart = ChartFactory.createXYAreaChart( computeTitle(), getDomainTitle(), getRangeTitle(), xyDataset, orientation, isShowLegend(), false, false ); } } configureLogarithmicAxis( chart.getXYPlot() ); return chart; }
Example #20
Source File: YIntervalRenderer.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). */ private void drawAdditionalItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y) { if (this.additionalItemLabelGenerator == null) { return; } Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = this.additionalItemLabelGenerator.generateLabel(dataset, series, item); ItemLabelPosition position = getNegativeItemLabelPosition(series, item); Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); }
Example #21
Source File: XYAreaChartTest.java From SIMVA-SoS with Apache License 2.0 | 6 votes |
/** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); }
Example #22
Source File: AbstractXYItemRenderer.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Adds an entity to the collection. * * @param entities the entity collection being populated. * @param area the entity area (if <code>null</code> a default will be * used). * @param dataset the dataset. * @param series the series. * @param item the item. * @param entityX the entity's center x-coordinate in user space (only * used if <code>area</code> is <code>null</code>). * @param entityY the entity's center y-coordinate in user space (only * used if <code>area</code> is <code>null</code>). */ protected void addEntity(EntityCollection entities, Shape area, XYDataset dataset, int series, int item, double entityX, double entityY) { if (!getItemCreateEntity(series, item)) { return; } Shape hotspot = area; if (hotspot == null) { double r = getDefaultEntityRadius(); double w = r * 2; if (getPlot().getOrientation() == PlotOrientation.VERTICAL) { hotspot = new Ellipse2D.Double(entityX - r, entityY - r, w, w); } else { hotspot = new Ellipse2D.Double(entityY - r, entityX - r, w, w); } } String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) { tip = generator.generateToolTip(dataset, series, item); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, series, item); } XYItemEntity entity = new XYItemEntity(hotspot, dataset, series, item, tip, url); entities.add(entity); }
Example #23
Source File: DatasetUtilities.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Returns the range of values in the range for the dataset. This method * is the partner for the {@link #findDomainBounds(XYDataset, boolean)} * method. * * @param dataset the dataset (<code>null</code> not permitted). * @param includeInterval a flag that determines whether or not the * y-interval is taken into account. * * @return The range (possibly <code>null</code>). */ public static Range findRangeBounds(XYDataset dataset, boolean includeInterval) { ParamChecks.nullNotPermitted(dataset, "dataset"); Range result; if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; result = info.getRangeBounds(includeInterval); } else { result = iterateRangeBounds(dataset, includeInterval); } return result; }
Example #24
Source File: DatasetUtilitiesTest.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Some tests for the findMinimumDomainValue() method. */ @Test public void testFindMinimumDomainValue() { XYDataset dataset = createXYDataset1(); Number minimum = DatasetUtilities.findMinimumDomainValue(dataset); assertEquals(new Double(1.0), minimum); }
Example #25
Source File: HighLowRenderer.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Returns the range of values the renderer requires to display all the * items from 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). */ @Override public Range findRangeBounds(XYDataset dataset) { if (dataset != null) { return DatasetUtilities.findRangeBounds(dataset, true); } else { return null; } }
Example #26
Source File: DatasetUtilitiesTest.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Some checks for the sampleFunction2D() method. */ @Test public void testSampleFunction2D() { Function2D f = new LineFunction2D(0, 1); XYDataset dataset = DatasetUtilities.sampleFunction2D(f, 0.0, 1.0, 2, "S1"); assertEquals(1, dataset.getSeriesCount()); assertEquals("S1", dataset.getSeriesKey(0)); assertEquals(2, dataset.getItemCount(0)); assertEquals(0.0, dataset.getXValue(0, 0), EPSILON); assertEquals(0.0, dataset.getYValue(0, 0), EPSILON); assertEquals(1.0, dataset.getXValue(0, 1), EPSILON); assertEquals(1.0, dataset.getYValue(0, 1), EPSILON); }
Example #27
Source File: SWTTimeSeriesDemo.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Creates a chart. * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart( "Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); 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); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
Example #28
Source File: MovingAverage.java From SIMVA-SoS with Apache License 2.0 | 5 votes |
/** * Creates a new {@link XYDataset} containing the moving averages of each * series in the <code>source</code> dataset. * * @param source the source dataset. * @param suffix the string to append to source series names to create * target series names. * @param period the averaging period. * @param skip the length of the initial skip period. * * @return The dataset. */ public static XYDataset createMovingAverage(XYDataset source, String suffix, double period, double skip) { ParamChecks.nullNotPermitted(source, "source"); XYSeriesCollection result = new XYSeriesCollection(); for (int i = 0; i < source.getSeriesCount(); i++) { XYSeries s = createMovingAverage(source, i, source.getSeriesKey(i) + suffix, period, skip); result.addSeries(s); } return result; }
Example #29
Source File: TimeSeriesChartDemo1.java From opensim-gui with Apache License 2.0 | 5 votes |
/** * Creates a chart. * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart( "Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); 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); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
Example #30
Source File: XYPlotToolTipGenerator.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override public String generateToolTip(XYDataset data, int series, int item) { final Comparable key = data.getSeriesKey(series); final double valueX = data.getXValue(series, item); final double valueY = data.getYValue(series, item); return String.format("%s: X = %6.2f, Y = %6.2f", key, valueX, valueY); }