I'm using an adapted version of the Dynamic Data Demo 3 graph from the library, and I would like to change the thickness of the line and reset the graph at the push of a button, in other words have both x & y axis reset to 0 and start again.
Are there ways of doing this?
This is the basic code I'm using to initialise the chart:
Code: Select all
/** The number of subplots. */
public static final int SUBPLOT_COUNT = 1;
/** The datasets. */
protected XYSeriesCollection[] datasets;
/** The most recent value added to series 1. */
protected double[] lastValue = new double[SUBPLOT_COUNT];
JPanel content;
ChartPanel chartPanel;
final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("intervals"));
this.datasets = new XYSeriesCollection[SUBPLOT_COUNT];
this.lastValue[0] = 100.0;
final XYSeries series = new XYSeries("Seconds");
this.datasets[0] = new XYSeriesCollection(series);
final NumberAxis rangeAxis = new NumberAxis("tx");
rangeAxis.configure();
rangeAxis.setAutoRangeIncludesZero(true);
final XYPlot subplot = new XYPlot(
this.datasets[0], null, rangeAxis, new StandardXYItemRenderer()
);
subplot.setBackgroundPaint(Color.black);
subplot.setDomainGridlinePaint(Color.white);
subplot.setRangeGridlinePaint(Color.white);
subplot.setRangeCrosshairPaint(Color.white);
subplot.getRenderer().setSeriesPaint(0, Color.green);
plot.add(subplot);
final JFreeChart chart = new JFreeChart("Demo", plot);
chart.setBorderPaint(Color.black);
chart.setBorderVisible(true);
chart.setBackgroundPaint(Color.white);
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
final ValueAxis axis = plot.getDomainAxis();
axis.setAutoRange(true);
content = new JPanel(new BorderLayout());
chartPanel = new ChartPanel(chart);
content.add(chartPanel);
Code: Select all
int iteration = 1;
while(true){
if(new File(filePath.getPath() + "/" + "end.txt").exists()){
iteration = 1;
//reset axis here.
File f = new File(filePath.getPath()+"/" + "end.txt");
f.delete();
}
else{
try{
File file = new File (filePath.getPath() + "/"+ (iteration) + ".txt");
BufferedReader scan = new BufferedReader(new FileReader(file));
boolean reading = true;
while(reading){
String X = scan.readLine();
if(X.equals("null")){
break;
}
double time = Double.parseDouble(X);
String Y= scan.readLine();
double tx = Double.parseDouble(Y);
final Millisecond now = new Millisecond();
System.out.println("Now = " + now.toString());
demo.lastValue[0] = time;
demo.datasets[0].getSeries(0).add(demo.lastValue[0], tx);
scan.close();
file.delete();
reading = false;
Thread.sleep(1000);
iteration++;
}
}
catch(FileNotFoundException FNF){
System.out.println("File not found");
continue;
}
catch(IOException IOE){
}
catch(InterruptedException IE){
}
}
Euden