@SuppressWarnings("deprecation") private static JFreeChart createChart( int[] dataTitles, String title, String xaxisName, String yaxisName) { TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeSeries = new TimeSeries[dataTitles.length]; for (int i = 0; i < timeSeries.length; i++) { timeSeries[i] = new TimeSeries("No." + dataTitles[i], Millisecond.class); timeseriescollection.addSeries(timeSeries[i]); } JFreeChart jfreechart = ChartFactory.createTimeSeriesChart( title, xaxisName, yaxisName, timeseriescollection, true, true, false); XYPlot xyplot = jfreechart.getXYPlot(); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); long t = 7200; valueaxis.setFixedAutoRange(t * 1000D); valueaxis = xyplot.getRangeAxis(); // valueaxis.setRange(0.0D,200D); return jfreechart; }
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset. * @throws Exception */ private static XYDataset createDataset(int id) throws Exception { TimeSeries s2 = new TimeSeries("Linea Uscite"); TimeSeries s1 = new TimeSeries("Linea Entrate"); boolean controllo = true; ArrayList<entrate> datiEntrate = EntrateDAO.getEntrate(id); ArrayList<uscite> datiUscite = UsciteDAO.getUscite(id); for (entrate e : datiEntrate) { s1.add( new Day(e.getData().getDate(), e.getData().getMonth() + 1, e.getData().getYear() + 1900), e.getQuantita()); } for (uscite e : datiUscite) { s2.add( new Day(e.getData().getDate(), e.getData().getMonth() + 1, e.getData().getYear() + 1900), e.getQuantita()); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }
public XYDataset createwrit() { TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(this.t_bwrit); timeseriescollection.addSeries(this.t_lwrit); timeseriescollection.addSeries(this.t_pwrit); return timeseriescollection; }
private static XYDataset createDataset() { TimeSeries timeseries = new TimeSeries("L&G European Index Trust"); timeseries.add(new Day(24, 1, 2004), 181.80000000000001D); timeseries.add(new Day(25, 1, 2004), 167.30000000000001D); timeseries.add(new Day(26, 1, 2004), 153.80000000000001D); timeseries.add(new Day(27, 1, 2004), 167.59999999999999D); timeseries.add(new Day(28, 1, 2004), 158.80000000000001D); timeseries.add(new Day(29, 1, 2004), 148.30000000000001D); timeseries.add(new Day(30, 1, 2004), 153.90000000000001D); timeseries.add(new Day(31, 1, 2004), 142.69999999999999D); timeseries.add(new Day(1, 2, 2004), 123.2D); timeseries.add(new Day(2, 2, 2004), 131.80000000000001D); timeseries.add(new Day(3, 2, 2004), 139.59999999999999D); timeseries.add(new Day(4, 2, 2004), 142.90000000000001D); timeseries.add(new Day(5, 2, 2004), 138.69999999999999D); timeseries.add(new Day(6, 2, 2004), 137.30000000000001D); timeseries.add(new Day(7, 2, 2004), 143.90000000000001D); timeseries.add(new Day(8, 2, 2004), 139.80000000000001D); timeseries.add(new Day(9, 2, 2004), 137D); timeseries.add(new Day(10, 2, 2004), 132.80000000000001D); TimeZone timezone = TimeZone.getTimeZone("Pacific/Auckland"); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timezone); timeseriescollection.addSeries(timeseries); timeseriescollection.setXPosition(TimePeriodAnchor.MIDDLE); return timeseriescollection; }
public XYDataset createread() { TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(this.t_bread); timeseriescollection.addSeries(this.t_lread); timeseriescollection.addSeries(this.t_pread); return timeseriescollection; }
private static XYDatasetMinMax createDeltaDataset( String name, SortedMap<TimeAxisKey, DiffStat> aggregatedDiffstats) { TimeSeriesCollection dataset = new TimeSeriesCollection(); int minimum = 0; int maximum = 0; TimeSeries addedSeries = new TimeSeries(name); TimeSeries removedSeries = new TimeSeries(name); for (Entry<TimeAxisKey, DiffStat> entry : aggregatedDiffstats.entrySet()) { TimeAxisKey timeAxisKey = entry.getKey(); DiffStat diffStat = entry.getValue(); RegularTimePeriod period = timeAxisKey.toPeriod(); int added = diffStat.added(); maximum = max(maximum, added); addedSeries.add(period, Integer.valueOf(added)); int removed = -diffStat.removed(); minimum = min(minimum, removed); removedSeries.add(period, Integer.valueOf(removed)); } dataset.addSeries(addedSeries); dataset.addSeries(removedSeries); return new XYDatasetMinMax(dataset, minimum, maximum); }
private TimeSeriesCollection createTotalDataset() { List<BigDecimal> values = intervalReport.getValues(); DateIterator dateIterator = intervalReport.dateIterator(); List<BigDecimal> inventoryValues = intervalReport.getInventoryValues(); List<BigDecimal> investmentValues = intervalReport.getInvestmentValues(); TimeSeries s1 = new TimeSeries(getEditorInput().getName(), Day.class); TimeSeries s2 = new TimeSeries("Invested sum", Day.class); BigDecimal sum = BigDecimal.ZERO; Iterator<BigDecimal> iterator1 = inventoryValues.iterator(); Iterator<BigDecimal> iterator2 = investmentValues.iterator(); for (BigDecimal v : values) { sum = sum.add(v); de.tomsplayground.util.Day d = dateIterator.next(); Day day = new Day(d.day, d.month + 1, d.year); BigDecimal v1 = sum.add(iterator1.next()); s1.add(day, v1); BigDecimal v2 = iterator2.next(); s2.add(day, v2); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }
public void setLineDisplay(String item, boolean selected) { TimeSeries t = stateMap.get(item); if (selected) { timeseriescollection.addSeries(t); } else { timeseriescollection.removeSeries(t); } updateColor(); }
public void clearAllData() { int len = timeseriescollection.getSeriesCount(); if (len != 0) { for (int i = 0; i < len; i++) { timeseriescollection.getSeries(i).clear(); } m_average.clear(); } }
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset. */ private static XYDataset createDataset() { TimeSeries s1 = new TimeSeries("L&G European Index Trust"); s1.add(new Month(2, 2001), 181.8); s1.add(new Month(3, 2001), 167.3); s1.add(new Month(4, 2001), 153.8); s1.add(new Month(5, 2001), 167.6); s1.add(new Month(6, 2001), 158.8); s1.add(new Month(7, 2001), 148.3); s1.add(new Month(8, 2001), 153.9); s1.add(new Month(9, 2001), 142.7); s1.add(new Month(10, 2001), 123.2); s1.add(new Month(11, 2001), 131.8); s1.add(new Month(12, 2001), 139.6); s1.add(new Month(1, 2002), 142.9); s1.add(new Month(2, 2002), 138.7); s1.add(new Month(3, 2002), 137.3); s1.add(new Month(4, 2002), 143.9); s1.add(new Month(5, 2002), 139.8); s1.add(new Month(6, 2002), 137.0); s1.add(new Month(7, 2002), 132.8); TimeSeries s2 = new TimeSeries("L&G UK Index Trust"); s2.add(new Month(2, 2001), 129.6); s2.add(new Month(3, 2001), 123.2); s2.add(new Month(4, 2001), 117.2); s2.add(new Month(5, 2001), 124.1); s2.add(new Month(6, 2001), 122.6); s2.add(new Month(7, 2001), 119.2); s2.add(new Month(8, 2001), 116.5); s2.add(new Month(9, 2001), 112.7); s2.add(new Month(10, 2001), 101.5); s2.add(new Month(11, 2001), 106.1); s2.add(new Month(12, 2001), 110.3); s2.add(new Month(1, 2002), 111.7); s2.add(new Month(2, 2002), 111.0); s2.add(new Month(3, 2002), 109.6); s2.add(new Month(4, 2002), 113.2); s2.add(new Month(5, 2002), 111.6); s2.add(new Month(6, 2002), 108.8); s2.add(new Month(7, 2002), 101.6); // ****************************************************************** // More than 150 demo applications are included with the JFreeChart // Developer Guide...for more information, see: // // > http://www.object-refinery.com/jfreechart/guide.html // // ****************************************************************** TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); return dataset; }
public Dataset getCustomDataset() { TimeSeriesCollection dataset = new TimeSeriesCollection(getTimeZone()); if (seriesNames != null) { for (int i = 0; i < seriesNames.size(); i++) { Comparable<?> seriesName = seriesNames.get(i); dataset.addSeries(seriesMap.get(seriesName)); } } return dataset; }
/** * @param forecast * @param settings (next days) * @return */ public JFreeChart createBarChart( final LiquidityForecast forecast, final LiquidityForecastSettings settings) { Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500); final LiquidityForecastCashFlow cashFlow = new LiquidityForecastCashFlow(forecast, settings.getNextDays()); final TimeSeries accumulatedSeriesExpected = new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.expected")); final TimeSeries creditSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.common.credit")); final TimeSeries debitSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.common.debit")); double accumulatedExpected = settings.getStartAmount().doubleValue(); final DayHolder dh = new DayHolder(); final Date lower = dh.getDate(); for (int i = 0; i < settings.getNextDays(); i++) { final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear()); if (i > 0) { accumulatedExpected += cashFlow.getDebitsExpected()[i - 1].doubleValue() + cashFlow.getCreditsExpected()[i - 1].doubleValue(); } accumulatedSeriesExpected.add(day, accumulatedExpected); creditSeries.add(day, cashFlow.getCreditsExpected()[i].doubleValue()); debitSeries.add(day, cashFlow.getDebitsExpected()[i].doubleValue()); dh.add(Calendar.DATE, 1); } dh.add(Calendar.DATE, -1); final XYChartBuilder cb = new XYChartBuilder( ChartFactory.createXYBarChart( null, null, false, null, null, PlotOrientation.VERTICAL, false, false, false)); int counter = 0; final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection(); xyDataSeries.addSeries(accumulatedSeriesExpected); final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, true); lineRenderer.setSeriesPaint(0, cb.getRedMarker()); lineRenderer.setSeriesVisibleInLegend(0, true); cb.setRenderer(counter, lineRenderer) .setDataset(counter++, xyDataSeries) .setStrongStyle(lineRenderer, false, accumulatedSeriesExpected); final TimeSeriesCollection cashflowSet = new TimeSeriesCollection(); cashflowSet.addSeries(debitSeries); cashflowSet.addSeries(creditSeries); final XYBarRenderer barRenderer = new XYBarRenderer(.2); barRenderer.setSeriesPaint(0, cb.getGreenFill()); barRenderer.setSeriesPaint(1, cb.getRedFill()); barRenderer.setShadowVisible(false); cb.setRenderer(counter, barRenderer).setDataset(counter++, cashflowSet); cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null); return cb.getChart(); }
/** Trims and transforms a big burndown chart to a small one. */ protected JFreeChart transformToSmallChart(JFreeChart burndownChart) { JFreeChart chart = burndownChart; XYPlot plot = chart.getXYPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); chart.setBackgroundPaint(CHART_BACKGROUND_COLOR); plot.setBackgroundPaint(PLOT_BACKGROUND_COLOR); renderer.setSeriesPaint(BURNDOWN_SERIES_NO, BURNDOWN_SERIES_COLOR); renderer.setSeriesPaint(CURRENT_DAY_SERIES_NO, BURNDOWN_SERIES_COLOR); renderer.setSeriesPaint(SCOPING_SERIES_NO, BURNDOWN_SERIES_COLOR); renderer.setSeriesPaint(REFERENCE_SERIES_NO, REFERENCE_SERIES_COLOR); renderer.setSeriesStroke(BURNDOWN_SERIES_NO, SMALL_BURNDOWN_STROKE); renderer.setSeriesStroke(CURRENT_DAY_SERIES_NO, SMALL_BURNDOWN_STROKE); renderer.setSeriesStroke(SCOPING_SERIES_NO, SMALL_BURNDOWN_STROKE); renderer.setSeriesStroke(REFERENCE_SERIES_NO, SMALL_BURNDOWN_STROKE); renderer.setSeriesShapesVisible(BURNDOWN_SERIES_NO, false); renderer.setSeriesShapesVisible(CURRENT_DAY_SERIES_NO, false); renderer.setSeriesShapesVisible(SCOPING_SERIES_NO, false); renderer.setSeriesShapesVisible(REFERENCE_SERIES_NO, false); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); plot.getDomainAxis().setVisible(false); plot.getRangeAxis().setVisible(false); plot.getDomainAxis().setLabel(null); plot.getRangeAxis().setLabel(null); RectangleInsets ins = new RectangleInsets(-6, -8, -3, -7); chart.setPadding(ins); if (plot.getDataset() != null) { TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset(); // HORROR! // Will break horribly if some series is missing because the indexes // cannot be trusted!! // The indexes are defined as constants but the indexes come // directly // from the order in which the series are added // If one series is missing, EXPECTED_SERIES_NO = 4 but the index // for expected series is 3 // (and it's even possible that it doesn't exist!) if (dataset.getSeriesCount() > EXPECTED_SERIES_NO) { dataset.removeSeries(EXPECTED_SERIES_NO); } } chart.removeLegend(); chart.setTitle(""); return chart; }
private static XYDataset createDataset() { s1_mensuel = new TimeSeries("total_portefeuille"); Gestion_base_de_donnee.recuperertotaux(); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1_mensuel); return dataset; }
/** wipes all data */ public void wipeAll() { // wipes all dataset1.removeAllSeries(); x1 = new TimeSeries("symbol", FixedMillisecond.class); dataset1.addSeries(x1); current = new Candle(); candletime = -1; hld.wipe(); }
@Override public void newCapabilityValues(java.util.List<CapabilityValue> values) { log.debug("Got new capabilities to update visualization"); for (CapabilityValue value : values) { Measurement measurement = measurements.get(value.getMetricsId()); if (data.getSeries(measurement.getLabel()) == null) { data.addSeries(new TimeSeries(measurement.getLabel())); } data.getSeries(measurement.getLabel()) .addOrUpdate(new Second(value.getGatherTimestamp()), value.getNumericValue()); log.debug("Amount of series: {}", data.getSeries().size()); } }
public XYDataset createused() { TimeSeriesCollection graphcollection = new TimeSeriesCollection(); graphcollection.addSeries(this.t_usr); graphcollection.addSeries(this.t_sys); if (cpuOpt.equals("%iowait")) { graphcollection.addSeries(this.t_wio); } if (cpuOpt.equals("%steal")) { graphcollection.addSeries(this.t_wio); graphcollection.addSeries(this.t_steal); } return graphcollection; }
public Chart(String filename) { try { // Get Stock Symbol this.stockSymbol = filename.substring(0, filename.indexOf('.')); // Create time series TimeSeries open = new TimeSeries("Open Price", Day.class); TimeSeries close = new TimeSeries("Close Price", Day.class); TimeSeries high = new TimeSeries("High", Day.class); TimeSeries low = new TimeSeries("Low", Day.class); TimeSeries volume = new TimeSeries("Volume", Day.class); BufferedReader br = new BufferedReader(new FileReader(filename)); String key = br.readLine(); String line = br.readLine(); while (line != null && !line.startsWith("<!--")) { StringTokenizer st = new StringTokenizer(line, ",", false); Day day = getDay(st.nextToken()); double openValue = Double.parseDouble(st.nextToken()); double highValue = Double.parseDouble(st.nextToken()); double lowValue = Double.parseDouble(st.nextToken()); double closeValue = Double.parseDouble(st.nextToken()); long volumeValue = Long.parseLong(st.nextToken()); // Add this value to our series' open.add(day, openValue); close.add(day, closeValue); high.add(day, highValue); low.add(day, lowValue); // Read the next day line = br.readLine(); } // Build the datasets dataset.addSeries(open); dataset.addSeries(close); dataset.addSeries(low); dataset.addSeries(high); datasetOpenClose.addSeries(open); datasetOpenClose.addSeries(close); datasetHighLow.addSeries(high); datasetHighLow.addSeries(low); JFreeChart summaryChart = buildChart(dataset, "Summary", true); JFreeChart openCloseChart = buildChart(datasetOpenClose, "Open/Close Data", false); JFreeChart highLowChart = buildChart(datasetHighLow, "High/Low Data", true); JFreeChart highLowDifChart = buildDifferenceChart(datasetHighLow, "High/Low Difference Chart"); // Create this panel this.setLayout(new GridLayout(2, 2)); this.add(new ChartPanel(summaryChart)); this.add(new ChartPanel(openCloseChart)); this.add(new ChartPanel(highLowChart)); this.add(new ChartPanel(highLowDifChart)); } catch (Exception e) { e.printStackTrace(); } }
private static XYDataset createForceDataset(int i) { TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); TimeSeries timeseries = new TimeSeries("Wind Force", org.jfree.data.time.Minute.class); Object obj = new Minute(); double d = 3D; for (int j = 0; j < i; j++) { timeseries.add(((RegularTimePeriod) (obj)), d); obj = ((RegularTimePeriod) (obj)).next(); d = Math.max(0.5D, d + (Math.random() - 0.5D) * 0.5D); } timeseriescollection.addSeries(timeseries); return timeseriescollection; }
private static XYDataset createDataset() { TimeSeries timeseries = new TimeSeries("Heart Rate"); timeseries.add(new Second(45, 6, 9, 1, 10, 2006), 143D); timeseries.add(new Second(33, 8, 9, 1, 10, 2006), 167D); timeseries.add(new Second(10, 10, 9, 1, 10, 2006), 189D); timeseries.add(new Second(19, 12, 9, 1, 10, 2006), 156D); timeseries.add(new Second(5, 15, 9, 1, 10, 2006), 176D); timeseries.add(new Second(12, 16, 9, 1, 10, 2006), 183D); timeseries.add(new Second(6, 18, 9, 1, 10, 2006), 138D); timeseries.add(new Second(11, 20, 9, 1, 10, 2006), 102D); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(timeseries); return timeseriescollection; }
/** * A demonstration application showing how to create a time series chart with multiple axes. * * @param title1 the frame title. * @param xaxis1 xaxis title * @param yaxis1 yaxis title * @param series1 the data */ public MultipleAxisChart(String title1, String xaxis1, String yaxis1, TimeSeries series1) { TimeSeriesCollection dataset1 = new TimeSeriesCollection(); dataset1.addSeries(series1); chart = ChartFactory.createTimeSeriesChart(title1, xaxis1, yaxis1, dataset1, true, true, false); // chart.addSubtitle(new TextTitle("Four datasets and four range axes.")); XYPlot plot = (XYPlot) chart.getPlot(); plot.setOrientation(PlotOrientation.VERTICAL); plot.getRangeAxis().setFixedDimension(15.0); this.setLayout(new BorderLayout()); this.add(new ChartPanel(chart), BorderLayout.CENTER); }
private XYDataset createDataset( String s, double d, RegularTimePeriod regulartimeperiod, int i) { series = new TimeSeries(s); RegularTimePeriod regulartimeperiod1 = regulartimeperiod; double d1 = d; for (int j = 0; j < i; j++) { series.add(regulartimeperiod1, d1); regulartimeperiod1 = regulartimeperiod1.next(); d1 *= 1.0D + (Math.random() - 0.495D) / 10D; } TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(series); return timeseriescollection; }
public StatusDataset() { invocationCountDataset = new TimeSeriesCollection(new TimeSeries("Invocation count", Minute.class)); // Maximum and average response time are placed in a collection together maxResponseTimeSeries = new TimeSeries("Max response time", Minute.class); avgResponseTimeSeries = new TimeSeries("Avg response time", Minute.class); responseTimeDataset = new TimeSeriesCollection(maxResponseTimeSeries); responseTimeDataset.addSeries(avgResponseTimeSeries); // Checked and unchecked are also placed in same TimeSeriesCollection uncheckedExceptionsDataset = new TimeSeries("Unchecked exceptions", Minute.class); checkedExceptionsDataset = new TimeSeries("Checked exceptions", Minute.class); exceptionDataset = new TimeSeriesCollection(uncheckedExceptionsDataset); exceptionDataset.addSeries(checkedExceptionsDataset); }
private static IntervalXYDataset createDataset() { TimeSeries timeseries = new TimeSeries("Series 1"); timeseries.add(new Day(1, 1, 2003), 54.299999999999997D); timeseries.add(new Day(2, 1, 2003), 20.300000000000001D); timeseries.add(new Day(3, 1, 2003), 43.399999999999999D); timeseries.add(new Day(4, 1, 2003), -12D); TimeSeries timeseries1 = new TimeSeries("Series 2"); timeseries1.add(new Day(1, 1, 2003), 8D); timeseries1.add(new Day(2, 1, 2003), 16D); timeseries1.add(new Day(3, 1, 2003), 21D); timeseries1.add(new Day(4, 1, 2003), 5D); TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(); timeseriescollection.addSeries(timeseries); timeseriescollection.addSeries(timeseries1); return timeseriescollection; }
public Chart(String title, String timeAxis, String valueAxis, TimeSeries data) { try { // Build the datasets dataset.addSeries(data); // Create the chart JFreeChart chart = ChartFactory.createTimeSeriesChart( title, timeAxis, valueAxis, dataset, true, true, false); // Setup the appearance of the chart chart.setBackgroundPaint(Color.white); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(UnitType.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); // Tell the chart how we would like dates to read DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("EEE HH")); this.add(new ChartPanel(chart)); } catch (Exception e) { e.printStackTrace(); } }
private void init() { timeSeriesList = new LinkedList<TimeSeries>(); m_average = new TimeSeries(AVERANGE, Millisecond.class); m_tps = new TimeSeries(TPS, Millisecond.class); m_deviation = new TimeSeries(DEVIATION, Millisecond.class); stateMap.put(AVERANGE, m_average); stateMap.put(DEVIATION, m_deviation); stateMap.put(TPS, m_tps); timeSeriesList.add(m_average); timeSeriesList.add(m_tps); timeSeriesList.add(m_deviation); timeseriescollection = new TimeSeriesCollection(); for (Iterator<TimeSeries> iterator = timeSeriesList.iterator(); iterator.hasNext(); ) { timeseriescollection.addSeries(iterator.next()); } jfc = ChartFactory.createTimeSeriesChart( "Title", "unit", "yaxisName", timeseriescollection, true, true, false); // jfc.setTitle(new TextTitle("图表", new Font("黑体", Font.BOLD, 20))); // 取得统计图表 XYPlot xyplot = jfc.getXYPlot(); xylinerenderer = (XYLineAndShapeRenderer) xyplot.getRenderer(); xylinerenderer.setSeriesPaint(0, Color.BLUE); xylinerenderer.setSeriesPaint(1, Color.GREEN); xylinerenderer.setSeriesPaint(2, Color.RED); ValueAxis valueaxis = xyplot.getDomainAxis(); valueaxis.setAutoRange(true); valueaxis.setFixedAutoRange(30000D); valueaxis = xyplot.getRangeAxis(); chartPanel = new ChartPanel(jfc); chartPanel.setPreferredSize(new Dimension(600, 450)); }
/** * Creates a sample dataset. * * @param name the dataset name. * @param base the starting value. * @param start the starting period. * @param count the number of values to generate. * @return The dataset. */ private XYDataset createDataset(String name, double base, RegularTimePeriod start, int count) { this.series = new TimeSeries(name, start.getClass()); RegularTimePeriod period = start; double value = base; for (int i = 0; i < count; i++) { this.series.add(period, value); period = period.next(); value = value * (1 + (Math.random() - 0.495) / 10.0); } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(this.series); return dataset; }
/* */ private static XYDataset createDataset() /* */ { /* 135 */ TimeSeries s1 = new TimeSeries("L&G European Index Trust"); /* 136 */ s1.add(new Month(2, 2001), 181.80000000000001D); /* 137 */ s1.add(new Month(3, 2001), 167.30000000000001D); /* 138 */ s1.add(new Month(4, 2001), 153.80000000000001D); /* 139 */ s1.add(new Month(5, 2001), 167.59999999999999D); /* 140 */ s1.add(new Month(6, 2001), 158.80000000000001D); /* 141 */ s1.add(new Month(7, 2001), 148.30000000000001D); /* 142 */ s1.add(new Month(8, 2001), 153.90000000000001D); /* 143 */ s1.add(new Month(9, 2001), 142.69999999999999D); /* 144 */ s1.add(new Month(10, 2001), 123.2D); /* 145 */ s1.add(new Month(11, 2001), 131.80000000000001D); /* 146 */ s1.add(new Month(12, 2001), 139.59999999999999D); /* 147 */ s1.add(new Month(1, 2002), 142.90000000000001D); /* 148 */ s1.add(new Month(2, 2002), 138.69999999999999D); /* 149 */ s1.add(new Month(3, 2002), 137.30000000000001D); /* 150 */ s1.add(new Month(4, 2002), 143.90000000000001D); /* 151 */ s1.add(new Month(5, 2002), 139.80000000000001D); /* 152 */ s1.add(new Month(6, 2002), 137.0D); /* 153 */ s1.add(new Month(7, 2002), 132.80000000000001D); /* */ /* 155 */ TimeSeries s2 = new TimeSeries("L&G UK Index Trust"); /* 156 */ s2.add(new Month(2, 2001), 129.59999999999999D); /* 157 */ s2.add(new Month(3, 2001), 123.2D); /* 158 */ s2.add(new Month(4, 2001), 117.2D); /* 159 */ s2.add(new Month(5, 2001), 124.09999999999999D); /* 160 */ s2.add(new Month(6, 2001), 122.59999999999999D); /* 161 */ s2.add(new Month(7, 2001), 119.2D); /* 162 */ s2.add(new Month(8, 2001), 116.5D); /* 163 */ s2.add(new Month(9, 2001), 112.7D); /* 164 */ s2.add(new Month(10, 2001), 101.5D); /* 165 */ s2.add(new Month(11, 2001), 106.09999999999999D); /* 166 */ s2.add(new Month(12, 2001), 110.3D); /* 167 */ s2.add(new Month(1, 2002), 111.7D); /* 168 */ s2.add(new Month(2, 2002), 111.0D); /* 169 */ s2.add(new Month(3, 2002), 109.59999999999999D); /* 170 */ s2.add(new Month(4, 2002), 113.2D); /* 171 */ s2.add(new Month(5, 2002), 111.59999999999999D); /* 172 */ s2.add(new Month(6, 2002), 108.8D); /* 173 */ s2.add(new Month(7, 2002), 101.59999999999999D); /* */ /* 183 */ TimeSeriesCollection dataset = new TimeSeriesCollection(); /* 184 */ dataset.addSeries(s1); /* 185 */ dataset.addSeries(s2); /* */ /* 187 */ return dataset; /* */ }
private XYDataset createDataset(StockInfo stock, StockPriceType priceType) { TimeSeries timeSeries = new TimeSeries(stock.getTickerSymbol()); for (StockData sd : stock.getStockData()) { cal.setTime(sd.getDate()); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); int year = cal.get(Calendar.YEAR); timeSeries.add(new Day(day, month + 1, year), priceType.get(sd)); // + 1 since calendar month starts at 0 } TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(timeSeries); return dataset; }
private void updateColor() { int len = timeseriescollection.getSeriesCount(); if (len != 0) { for (int i = 0; i < len; i++) { TimeSeries t = timeseriescollection.getSeries(i); if (t.getKey().equals(AVERANGE)) { xylinerenderer.setSeriesPaint(i, Color.BLUE); } else if (t.getKey().equals(TPS)) { xylinerenderer.setSeriesPaint(i, Color.GREEN); } else if (t.getKey().equals(DEVIATION)) { xylinerenderer.setSeriesPaint(i, Color.RED); } else { } } } }