I'm trying to use the AChartEngine library using a time series. The X axis is time, and Y axis are integer values.
The problem is that I could not setup a renderer.setXAxisMin and Max for the X axis for time. Either all the data points are crumbed together, or the time is apart so large that I cannot see any datapoints.
This is the classes I've used:
//For Chart 1
private static Random random = new Random();
private static TimeSeries timeSeries;
private static XYMultipleSeriesDataset dataset;
private static XYMultipleSeriesRenderer renderer;
private static XYSeriesRenderer rendererSeries;
private static GraphicalView view;
Initialization:
if(timeSeries == null)
{
//Chart 1
dataset = new XYMultipleSeriesDataset();
renderer = new XYMultipleSeriesRenderer();
timeSeries = new TimeSeries("Channel 1");
rendererSeries = new XYSeriesRenderer();
}
Renderer:
//For Chart 1
renderer.setAxesColor(Color.BLUE);
renderer.setAxisTitleTextSize(16);
renderer.setChartTitle("Real Time Seizure Monitoring Graph");
renderer.setChartTitleTextSize(15);
renderer.setFitLegend(true);
renderer.setGridColor(Color.LTGRAY);
renderer.setPanEnabled(true, true);
renderer.setPointSize(1);
renderer.setXTitle("Time");
renderer.setYTitle("Amplitude (DAC)");
renderer.setMargins( new int []{60, 60, 60, 60});
renderer.setZoomButtonsVisible(false);
renderer.setBarSpacing(10);
renderer.setShowGrid(true);
renderer.setLabelsColor(Color.BLUE);
renderer.setApplyBackgroundColor(true);
renderer.setBackgroundColor(Color.BLACK);
renderer.setAxisTitleTextSize(16);
renderer.setChartTitleTextSize(20);
renderer.setLabelsTextSize(15);
renderer.setLegendTextSize(15);
renderer.setZoomButtonsVisible(false);
renderer.setPointSize(5);
renderer.setXLabels(10);
renderer.setYLabels(10);
renderer.setShowGrid(true);
renderer.setXLabelsAlign(Align.CENTER);
renderer.setYLabelsAlign(Align.RIGHT);
renderer.setInScroll(true);
renderer.setXLabels(5);
//renderer.setXAxisMin(0.00000001);
//renderer.setXAxisMax(new Date().getTime());
//renderer.setXAxisMin(100);
//renderer.setXAxisMax(1000000);
renderer.addSeriesRenderer(rendererSeries);
rendererSeries.setFillPoints(true);
rendererSeries.setPointStyle(PointStyle.CIRCLE);
rendererSeries.setColor(Color.RED);
Adding the datasets and series:
//Setting for Chart 1
dataset.addSeries(timeSeries);
view = ChartFactory.getTimeChartView(this, dataset, renderer, "Real Time Seizure Monitoring Graph");
view.refreshDrawableState();
view.repaint();
Function to start inserting random variables:
void startTest()
{
mThread = new Thread()
{
public void run()
{
while(true)
{
try
{
Thread.sleep(2000L);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
//Chart 1 Random Data
int someInt = random.nextInt(4096);
timeSeries.add(new Date(), someInt);
timeSeries.addAnnotation(new Date().toString(), new Date().getTime(), someInt);
view.refreshDrawableState();
view.repaint();
}
}
};
mThread.start();
}
}
Without the set X axis min and max commented, the datapoints are updated with no problems, and all points are visible.
Furthermore, if there a lot of data points created by the thread, the panning appears to be very slow.