Old values in JFreechart removed

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
MeredithSmith
Posts: 1
Joined: Tue Apr 09, 2019 8:37 am
antibot: No, of course not.

Old values in JFreechart removed

Post by MeredithSmith » Tue Apr 09, 2019 8:40 am

Friends, in my project i just use the JFreechart. In that project i am getting bytes received value from the database. it change at every iteration. In Jfreechart it shows the correct point at iteration-1. But in iteration-2 it remove the old point and only shows for current value. Here i am using JFreechart. How to show value for old bytes received value also in the graph without remove? here is my code to generate timeseries chart.

Code: Select all

public static JFreeChart Chart;
TimeSeries Series = new TimeSeries("Random Data");
Second sec = new Second();
public static ChartPanel CPanel1;
XYDataset Dataset;
Value = Integer.parseInt(MySQLClass.Map_MySql.get(""+MainWindow.CounterName1+""));
Series.add(sec.previous().previous().previous().previous().previous().previous().previous().previous(), ExistingValue);
Series.add(sec, Value);
Dataset = new TimeSeriesCollection(Series);
TimeSeriesDataItem DataItem = Series.getDataItem(Series.getItemCount()-1); // For getting Annotiation.
Chart = null;
Chart = ChartFactory.createTimeSeriesChart(MainWindow.CounterName1, "Current Time", "Counter Value", Dataset, true, true, true);
// To find the location for Annotiation.
double x = DataItem.getPeriod().getFirstMillisecond();
double y = DataItem.getValue().doubleValue();
XYPointerAnnotation a = new XYPointerAnnotation(MainWindow.CounterName1, x, y, Value);
XYPlot Plot = (XYPlot)Chart.getPlot();
Plot.addAnnotation(a); // Connecting Plot with Annotiation.
// For setting the Renderer.
XYItemRenderer ItemRenderer = Plot.getRenderer();
if(ItemRenderer instanceof XYLineAndShapeRenderer)
{
XYLineAndShapeRenderer LineAndShapeRenderer = (XYLineAndShapeRenderer) ItemRenderer;
LineAndShapeRenderer.setBaseShapesVisible(true);
LineAndShapeRenderer.setBaseShapesFilled(true);
LineAndShapeRenderer.setDrawSeriesLineAsPath(true);
}
Plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
DateFormat formatter = new SimpleDateFormat("hh:mm:ss a");
DateAxis axis = (DateAxis) Plot.getDomainAxis();
axis.setDateFormatOverride(formatter);
CPanel1 = new ChartPanel(Chart);
Panel2.revalidate();
Panel2.add(CPanel1);
Panel2.validate();
CPanel1.repaint();
System.gc();
ExistingValue = Integer.parseInt(MySQLClass.Map_MySql.get(""+MainWindow.CounterName1+""));
new MySQLClass().execute();
Here i am using swingworker to collect data from the database. it just display graph for current value. There is no other previous value in it. How can i add new value with old grpah value?

Post Reply