问题
As TimeSeries Construstor of AchartEngine API take only string as argument and have no other argument to pass as a scale argument. So how I will use it with two different scales
Thanks
回答1:
I suggest you don't try to use TimeSeries
for multiple scales charting.
You would better build a regular multiple scale line chart, set timestamps on the X axis and set your custom labels.
// disable the default labels
renderer.setXLabels(0);
// add your formatted dates, several of these calls
renderer.addXTextLabel(x, "formatted date");
回答2:
I would like to propose a simpler solution.
The reason that you can't have multiple scale groups with TimeSeries is simply because the authors forgot (or didn't feel the need) to add the necessary constructor to allow you to set which scale group the series should belong to. TimeSeries is a subclass of XYSeries and is incredibly simple (find the source here). The only special thing it does is give you an add method that takes a Date rather than a double. In fact, the add method in TimeSeries just makes the following call which passes in the x value as the millisecond time:
super.add(x.getTime(), y);
So the easiest way to accomplish what you want to do is to use a TimeChart, but instead of using a TimeSeries, use an XYSeries and just pass your dates in as milliseconds (just like TimeSeries does!). With this approach, you don't need to mess with the custom x axis labels.
Another approach might be to just write your own subclass of XYSeries.
Hopefully, the necessary constructor will be added to TimeSeries in the future so none of this will be necessary.
Better solution I found that it is better to just sub-class XYSeries with my own TimeSeries with the necessary constructor to support the scale group. This is because there is a padding value in the XYSeries which is overridden in TimeSeries. So, using the XYSeries for time can have problems due to that padding value. Here is the simple subclass that I'm using (notice the getPadding method returning 1, you need to have that):
private class MyTimeSeries extends XYSeries {
public MyTimeSeries(String title, int scaleNumber) {
super(title, scaleNumber);
}
public synchronized void add(Date x, double y) {
super.add(x.getTime(), y);
}
@Override
protected double getPadding(double x) {
return 1;
}
}
来源:https://stackoverflow.com/questions/12739561/achartengine-how-to-use-timeseries-with-two-different-scales