Reputation: 81
high guys i store numbers between 1 and 10 in a database and each number is stored with the time it was stored in the database. So i have two sets of data to plot number on the y axis and time on the x axis. however i want to do it in a way so that it plots time in hrs. So say i took 4 numbers in 2 hrs.e.g number 9 at 13:30, 10 at 14:00; 3 at 14:30, 5 at 15:00. plotting the axis is easy but the x axis gives me 2 problems when i want to plot it as a historical event meaning the name of the axis would be hrs and 0 on the axis would be the current time lets say renderer.addTextLabel(0, 15:07);
, then 1 on the axis would be the an hour ago or current time minus 60 minuites so renderer.addTextLabel(1, 14:07);
and finnaly 2 on the axis would be 2 hrs ago renderer.addTextLabel(2, 13:07);
.
the two problems i have with my graph is one because current time is a bigger value than the past times when the graph is plotted the x axis starts at 2 and goes down to 0 rather than starting at 0 and going up to two. secondly the graph increments in 100s rather than 60s which represent time. so any values of time than are lets say 13:59 and say 14:00 has a bigger gap between them were the graph assumes there should be values of numbers 13:60 or 13:80 or 13:99 which if we were counting would be true but obviously time goes up to 60 before incrementing the next number. How would i solve this problem? I am new to android and achartengine so please ask me to elaborate if you are unsure. thanks
Upvotes: 1
Views: 1581
Reputation: 1599
First, declare 2 renderers, one for your datas, one for your chart, and a TimeSeries.
renderer = new XYMultipleSeriesRenderer();
dataset = new XYMultipleSeriesDataset();
timeSeries = new TimeSeries("");
dataset.addSeries(timeSeries);
currentRenderer = new XYSeriesRenderer();
currentRenderer.setLineWidth(2);
currentRenderer.setFillPoints(true);
currentRenderer.setColor(Color.CYAN);
currentRenderer.setShowLegendItem(false);
renderer.addSeriesRenderer(currentRenderer);
Then add datas to your TimeSeries (with a Date, not a String or anything else)
Date date = format.parse(datasList.get(i).first);
timeSeries.add(date, datasList.get(i).second);
Set your chart then, add it to your view and paint it
charter.setChart(ChartFactory.getTimeChartView(view.getContext(),
charter.getDataset(), charter.getRenderer(), "%tT"));
layout.addView(charter.getChart(), 0, new LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
charter.getChart().repaint();
And that's it, normally you have a wonderful chart with TimeSeries
Upvotes: 2