/** * Creates a polar plot for the specified dataset (x-values interpreted as * angles in degrees). The chart object returned by this method uses a * {@link PolarPlot} instance as the plot, with a {@link NumberAxis} for * the radial axis. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param legend legend required? * @param tooltips tooltips required? * @param urls URLs required? * * @return A chart. */ public static JFreeChart createPolarChart(String title, XYDataset dataset, boolean legend, boolean tooltips, boolean urls) { PolarPlot plot = new PolarPlot(); plot.setDataset(dataset); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAxisLineVisible(false); rangeAxis.setTickMarksVisible(false); rangeAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); plot.setAxis(rangeAxis); plot.setRenderer(new DefaultPolarItemRenderer()); JFreeChart chart = new JFreeChart( title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
/** * Sets a dataset for the plot. * * @param index the dataset index. * @param dataset the dataset (<code>null</code> permitted). */ public void setDataset(int index, XYDataset dataset) { XYDataset existing = getDataset(index); if (existing != null) { existing.removeChangeListener(this); } this.datasets.set(index, dataset); if (dataset != null) { dataset.addChangeListener(this); } // map dataset to main axis by default if (index >= this.domainAxisMap.size()) { this.domainAxisMap.set(index, new Integer(0)); } if (index >= this.rangeAxisMap.size()) { this.rangeAxisMap.set(index, new Integer(0)); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); }
/** * 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); }
/** * Checks the results of a power regression on sample dataset 1 AFTER converting it to * an XYSeries. */ public void testPowerRegression1b() { final double[][] data = createSampleData1(); final XYSeries series = new XYSeries("Test"); for (int i = 0; i < 11; i++) { series.add(data[i][0], data[i][1]); } final XYDataset ds = new XYSeriesCollection(series); final double[] result = Regression.getPowerRegression(ds, 0); assertEquals(0.91045813, result[0], 0.0000001); assertEquals(0.88918346, result[1], 0.0000001); }
private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart( "MONA STORAGE GRAPH", "KeyGeneration per users ", "KeyGenerating size in Bytes", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot1 = chart.getXYPlot(); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); final XYPlot plot2 = chart.getXYPlot(); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); final XYPlot plot3 = chart.getXYPlot(); plot3.setBackgroundPaint(Color.lightGray); plot3.setDomainGridlinePaint(Color.white); plot3.setRangeGridlinePaint(Color.white); return chart; }
private void plotTradeBubblesOnChart(ArrayList<Integer> toPlot, String p, int k, int j) { final Plot main_plot = (Plot)((CombinedDomainXYPlot)this.candlestickChart.getPlot()).getSubplots().get(0); final XYPlot plot = (XYPlot) main_plot; final TimeSeries series = new TimeSeries(p); ///* for(Integer i: toPlot) { switch(j) { case 0: series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),chartDatas.get(i).getOpen()); break; case 1: series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),chartDatas.get(i).getHigh()); break; case 2: series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),chartDatas.get(i).getLow()); break; case 3: series.add(new Minute(new Date(chartDatas.get(i).getStartTimeStamp())),chartDatas.get(i).getClose()); break; } } /* for (int i = 0; i < defaultHighLowDataset.getSeriesCount(); i++) { series.add(new Minute(defaultHighLowDataset.getXDate(0, i)),plot[i]); } */ XYDataset dataSet = new TimeSeriesCollection(series); plot.setDataset(k, dataSet); XYItemRenderer ir = new XYShapeRenderer(); //ir.s plot.setRenderer(k, ir); }
/** * 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) { // check arguments if (source == null) { throw new IllegalArgumentException( "MovingAverage.createMovingAverage(...) : null source (XYDataset)." ); } final XYSeriesCollection result = new XYSeriesCollection(); for (int i = 0; i < source.getSeriesCount(); i++) { final XYSeries s = createMovingAverage(source, i, source.getSeriesName(i) + suffix, period, skip); result.addSeries(s); } return result; }
/** * Replaces the dataset and checks that it has changed as expected. */ 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); }
public KeySignatureGraph(String title, int one, int two) { super(title); XYDataset dataset = null; try { dataset = createDataset(one, two); } catch (Exception e) { System.out.println("MultiLineChart -- Constructor" + e); } final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 370)); setContentPane(chartPanel); this.pack(); RefineryUtilities.centerFrameOnScreen(this); this.setVisible(true); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); }
/** * Create a horizontal bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); // create the chart... return ChartFactory.createXYAreaChart( "Area Chart", // chart title "Domain", "Range", dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips true // urls ); }
@Override public void start(Stage stage) throws Exception { XYDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartCanvas canvas = new ChartCanvas(chart); StackPane stackPane = new StackPane(); stackPane.getChildren().add(canvas); // Bind canvas size to stack pane size. canvas.widthProperty().bind( stackPane.widthProperty()); canvas.heightProperty().bind( stackPane.heightProperty()); stage.setScene(new Scene(stackPane)); stage.setTitle("FXGraphics2DDemo1.java"); stage.setWidth(700); stage.setHeight(390); stage.show(); }
@Override public void start(Stage stage) throws Exception { XYDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); ChartViewer viewer = new ChartViewer(chart); stage.setScene(new Scene(viewer)); stage.setTitle("JFreeChart: TimeSeriesFXDemo1.java"); stage.setWidth(700); stage.setHeight(390); stage.show(); }
public static void main(String arg[]){ XYSeries series = new XYSeries("Average Weight"); series.add(20, 20); series.add(40, 25); series.add(55, 50); series.add(70, 65); // series.add(20.0, 20.0); // series.add(40.0, 25.0); // series.add(55.0, 50.0); // series.add(70.0, 65.0); XYDataset xyDataset = new XYSeriesCollection(series); JFreeChart chart = ChartFactory.createXYLineChart ("XYLine Chart using JFreeChart", "Age", "Weight", xyDataset, PlotOrientation.VERTICAL, true, true, false); ChartFrame frame1=new ChartFrame("XYLine Chart",chart); frame1.setVisible(true); frame1.setSize(300,300); }
/** * Returns the range of values in the range for the dataset. This method * is the partner for the {@link #findDomainBounds(XYDataset)} 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) { if (dataset == null) { throw new IllegalArgumentException("Null 'dataset' argument."); } Range result = null; if (dataset instanceof RangeInfo) { RangeInfo info = (RangeInfo) dataset; result = info.getRangeBounds(includeInterval); } else { result = iterateXYRangeBounds(dataset); } return result; }
/** * Creates a dataset for testing. * * @return A dataset. */ private XYDataset createXYDataset1() { XYSeries series1 = new XYSeries("S1"); series1.add(1.0, 100.0); series1.add(2.0, 101.0); series1.add(3.0, 102.0); XYSeries series2 = new XYSeries("S2"); series2.add(1.0, 103.0); series2.add(2.0, null); series2.add(3.0, 105.0); XYSeriesCollection result = new XYSeriesCollection(); result.addSeries(series1); result.addSeries(series2); result.setIntervalWidth(0.0); return result; }
/** * Creates a polar plot for the specified dataset (x-values interpreted as angles in degrees). * <P> * The chart object returned by this method uses a {@link PolarPlot} instance as the * plot, with a {@link NumberAxis} for the radial axis. * * @param title the chart title (<code>null</code> permitted). * @param dataset the dataset (<code>null</code> permitted). * @param legend legend required? * @param tooltips tooltips required? * @param urls URLs required? * * @return A chart. */ public static JFreeChart createPolarChart(String title, XYDataset dataset, boolean legend, boolean tooltips, boolean urls) { PolarPlot plot = new PolarPlot(); plot.setDataset(dataset); NumberAxis rangeAxis = new NumberAxis(); rangeAxis.setAxisLineVisible(false); rangeAxis.setTickMarksVisible(false); rangeAxis.setTickLabelInsets(new Insets(0, 0, 0, 0)); plot.setRadialAxis(rangeAxis); plot.setRenderer(new DefaultPolarItemRenderer()); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend); return chart; }
private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createXYLineChart("Auditing", "Fraction of Invalid Responses ", "Auding time for task(ms)", dataset, PlotOrientation.VERTICAL, true, true, false); chart.setBackgroundPaint(Color.white); final XYPlot plot1 = chart.getXYPlot(); plot1.setBackgroundPaint(Color.lightGray); plot1.setDomainGridlinePaint(Color.white); plot1.setRangeGridlinePaint(Color.white); final XYPlot plot2 = chart.getXYPlot(); plot2.setBackgroundPaint(Color.lightGray); plot2.setDomainGridlinePaint(Color.white); plot2.setRangeGridlinePaint(Color.white); final XYPlot plot3 = chart.getXYPlot(); plot3.setBackgroundPaint(Color.lightGray); plot3.setDomainGridlinePaint(Color.white); plot3.setRangeGridlinePaint(Color.white); return chart; }
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the plot is being drawn. * @param info collects info about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @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) { PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { drawHorizontalItem(g2, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); } else if (orientation == PlotOrientation.VERTICAL) { drawVerticalItem(g2, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item, crosshairState, pass); } }
/** * Calculates the stacked value of the all series up to, but not including <code>series</code> * for the specified category, <code>category</code>. It returns 0.0 if <code>series</code> * is the first series, i.e. 0. * * @param data the data. * @param series the series. * @param index the index. * * @return double returns a cumulative value for all series' values up to * but excluding <code>series</code> for <code>index</code>. */ protected double getPreviousHeight(XYDataset data, int series, int index) { double result = 0.0; Number tmp; for (int i = 0; i < series; i++) { tmp = data.getY(i, index); if (tmp != null) { result += tmp.doubleValue(); } } return result; }
/** * Returns a (possibly empty) collection of legend items for the series * that this renderer is responsible for drawing. * * @return The legend item collection (never <code>null</code>). */ public LegendItemCollection getLegendItems() { if (this.plot == null) { return new LegendItemCollection(); } LegendItemCollection result = new LegendItemCollection(); int index = this.plot.getIndexOf(this); XYDataset dataset = this.plot.getDataset(index); if (dataset != null) { int seriesCount = dataset.getSeriesCount(); for (int i = 0; i < seriesCount; i++) { if (isSeriesVisibleInLegend(i)) { LegendItem item = getLegendItem(index, i); if (item != null) { result.add(item); } } } } return result; }
public TimeandCostGraph(String title, int one, int two) { super(title); XYDataset dataset = null; try { dataset = createDataset(); } catch (Exception e) { System.out.println("MultiLineChart -- Constructor" + e); } final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(700, 470)); setContentPane(chartPanel); this.pack(); RefineryUtilities.centerFrameOnScreen(this); this.setVisible(true); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); }
/** * Creates a sample dataset. * * @return Series 2. */ private XYDataset createDataset2() { // create dataset 2... XYSeries series2 = new XYSeries("Series 3"); series2.add(10.0, 16853.2); series2.add(20.0, 19642.3); series2.add(30.0, 18253.5); series2.add(40.0, 15352.3); series2.add(50.0, 13532.0); series2.add(100.0, 12635.3); series2.add(110.0, 13998.2); series2.add(120.0, 11943.2); series2.add(130.0, 16943.9); series2.add(140.0, 17843.2); series2.add(150.0, 16495.3); series2.add(160.0, 17943.6); series2.add(170.0, 18500.7); series2.add(180.0, 19595.9); return new XYSeriesCollection(series2); }
public static void drawScatterPlot(final String title, final String xlabel, final String ylabel, final XYDataset dataset) { final JFrame frame = getFrame(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JPanel jpanel = new ScatterPlot(title, xlabel, ylabel).createPanel(dataset); frame.getContentPane().add(jpanel); frame.setVisible(true); } }); }
public JPanel createPanel(XYDataset dataset) { JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setVerticalAxisTrace(true); chartPanel.setHorizontalAxisTrace(true); chartPanel.setPopupMenu(null); chartPanel.setDomainZoomable(true); chartPanel.setRangeZoomable(true); return chartPanel; }
/** * Returns the range of values in the domain for the dataset. If the supplied dataset * is <code>null</code>, the range returned is <code>null</code>. * * @param dataset the dataset (<code>null</code> permitted). * * @return The range of values (possibly <code>null</code>). * * @deprecated Use findDomainExtent(XYDataset) instead. */ public static Range findDomainExtent(Dataset dataset) { // check parameters... if (dataset == null) { return null; } if ((dataset instanceof CategoryDataset) && !(dataset instanceof XYDataset)) { throw new IllegalArgumentException( "The dataset does not have a numerical domain." ); } // work out the minimum value... if (dataset instanceof DomainInfo) { DomainInfo info = (DomainInfo) dataset; return info.getDomainRange(); } // hasn't implemented DomainInfo, so iterate... else if (dataset instanceof XYDataset) { return iterateDomainExtent((XYDataset) dataset); } else { return null; // unrecognised dataset...how should this be handled? } }
/** * Creates a sample plot. * * @return A sample plot. */ private CombinedRangeXYPlot createPlot() { // create subplot 1... XYDataset data1 = createDataset1(); XYItemRenderer renderer1 = new StandardXYItemRenderer(); NumberAxis rangeAxis1 = new NumberAxis("Range 1"); XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1); subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT); XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0); annotation.setFont(new Font("SansSerif", Font.PLAIN, 9)); annotation.setRotationAngle(Math.PI / 4.0); subplot1.addAnnotation(annotation); // create subplot 2... XYDataset data2 = createDataset2(); XYItemRenderer renderer2 = new StandardXYItemRenderer(); NumberAxis rangeAxis2 = new NumberAxis("Range 2"); rangeAxis2.setAutoRangeIncludesZero(false); XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2); subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT); // parent plot... CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis("Range")); plot.setGap(10.0); // add the subplots... plot.add(subplot1, 1); plot.add(subplot2, 1); plot.setOrientation(PlotOrientation.VERTICAL); return plot; }
private JFreeChart createNumericalChart() { JFreeChart chart; XYDataset dataset = createNumericalDataSet(); // create the chart... String domainName = dataTable == null ? MODEL_DOMAIN_AXIS_NAME : dataTable.getColumnName(plotColumn); chart = ChartFactory.createXYLineChart(null, // chart title domainName, // x axis label RANGE_AXIS_NAME, // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); DeviationRenderer renderer = new DeviationRenderer(true, false); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); if (dataset.getSeriesCount() == 1) { renderer.setSeriesStroke(0, stroke); renderer.setSeriesPaint(0, Color.RED); renderer.setSeriesFillPaint(0, Color.RED); } else { for (int i = 0; i < dataset.getSeriesCount(); i++) { renderer.setSeriesStroke(i, stroke); Color color = getColorProvider().getPointColor((double) i / (double) (dataset.getSeriesCount() - 1)); renderer.setSeriesPaint(i, color); renderer.setSeriesFillPaint(i, color); } } renderer.setAlpha(0.12f); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRenderer(renderer); return chart; }
public static XYDataset createDefaultXYDataset(ValueSource valueSource, PlotInstance plotInstace) throws ChartPlottimeException { DefaultXYDataset dataset = new DefaultXYDataset(); ValueSourceData valueSourceData = plotInstace.getPlotData().getValueSourceData(valueSource); // assertMaxValueCountNotExceededOrThrowException(valueSourceData); for (int seriesIdx = 0; seriesIdx < valueSourceData.getSeriesCount(); ++seriesIdx) { addSeriesToDefaultXYDataset(valueSource, seriesIdx, plotInstace, dataset); } return dataset; }
/** * 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; }
/** * 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). */ public Range findRangeBounds(XYDataset dataset) { if (dataset != null) { Range r = DatasetUtilities.findRangeBounds(dataset, false); return new Range(r.getLowerBound() + this.yOffset, r.getUpperBound() + this.blockHeight + this.yOffset); } else { return null; } }
public JPanel paintPanel() { String titre = "Historique du point strat�gique"; String titre_x = "Periode"; String titre_y = "LED"; XYDataset dataset = createDataset(); JFreeChart chart = ChartFactory.createTimeSeriesChart(titre, titre_x, titre_y, dataset); return new ChartPanel(chart); }
protected XYDataset createDataset() { TimeSeriesCollection dataset = new TimeSeriesCollection(); DefaultKeyedValues data = new DefaultKeyedValues(); Date date = new Date(); dataset.addSeries(timeSeries); return dataset; }
private JFreeChart createPolarChart(final XYDataset dataset,String chartName) { if(chartName == null) chartName=FunctionToPlot; final JFreeChart chRt = ChartFactory.createPolarChart( chartName, dataset, true, true, false ); final PolarPlot plot = (PolarPlot) chRt.getPlot(); final DefaultPolarItemRenderer renderer = (DefaultPolarItemRenderer) plot.getRenderer(); renderer.setShapesVisible(false); //renderer.setShapesFilled(false); // renderer.setSeriesFilled(0, false); return chRt; }
private TimeSeries getTimeSeries(int plotIndex, int seriesIndex) { final ChartPanel chartPanel = this.chartJDialog.getChartPanel(); if (plotIndex >= chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotCount()) { /* Not ready yet. */ return null; } if (plotIndex >= this.chartJDialog.getPlotSize()) { /* Not ready yet. */ return null; } final XYDataset xyDataset = this.chartJDialog.getPlot(plotIndex).getDataset(); if (xyDataset instanceof TimeSeriesCollection) { final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection)xyDataset; if (seriesIndex >= timeSeriesCollection.getSeriesCount()) { return null; } return timeSeriesCollection.getSeries(seriesIndex); } else { // 0 is candlestick chart. if (plotIndex == 0 && seriesIndex == 0) { return null; } if (seriesIndex >= this.chartJDialog.getPlot(plotIndex).getDatasetCount()) { return null; } final XYDataset d = this.chartJDialog.getPlot(plotIndex).getDataset(seriesIndex); return ((TimeSeriesCollection)d).getSeries(0); } }
public ChartPanel getChartPanel(List<String> industrys) { XYDataset xydataset = createDataset(industrys); JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("行业资金流入流出", "日期(日/单位)", "价格(亿/单位)", xydataset, true, true, true); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis(); dateaxis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd")); dateaxis.setLabelFont(new Font("黑体", Font.BOLD, 14)); //水平底部标题 dateaxis.setTickLabelFont(new Font("宋体", Font.BOLD, 12)); //垂直标题 ValueAxis rangeAxis = xyplot.getRangeAxis();//获取柱状 rangeAxis.setLabelFont(new Font("黑体", Font.BOLD, 15)); jfreechart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15)); jfreechart.getTitle().setFont(new Font("宋体", Font.BOLD, 20));//设置标题字体 ChartPanel frame1 = new ChartPanel(jfreechart, true); return frame1; }
public JFreeChart createChart(final XYDataset dataset) { return ChartFactory.createTimeSeriesChart( feature, "Timestamp", "Value", dataset, true, false, false); }
public MyDemoPane() { XYDataset dataset = createDataset(); JFreeChart chart = createChart(dataset); this.chartViewer = new ChartViewer(chart); this.chartViewer.addChartMouseListener(this); getChildren().add(this.chartViewer); CrosshairOverlayFX crosshairOverlay = new CrosshairOverlayFX(); this.xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); this.xCrosshair.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[]{2.0f, 2.0f}, 0)); this.xCrosshair.setLabelVisible(true); this.yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); this.yCrosshair.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1, new float[] {2.0f, 2.0f}, 0)); this.yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); Platform.runLater(() -> { this.chartViewer.getCanvas().addOverlay(crosshairOverlay); }); }
/** * Returns the index of the specified dataset, or <code>-1</code> if the dataset * does not belong to the plot. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The index. */ public int indexOf(XYDataset dataset) { int result = -1; for (int i = 0; i < this.datasets.size(); i++) { if (dataset == this.datasets.get(i)) { result = i; break; } } return result; }