我从数据库中获取股票日期,其中公司的股票历史记录保存在数据库列中。每天的数据都以{date,stock_value}格式显示,并通过" \ n"与其他日期分开。
Access-Control-*
以下是points变量的内容: [[1.4887386E12 / 117.55000305175781],[1.4881338E12 / 118.62000274658203],[1.4876154E12 / 118.79000091552734]]
图表显示为: The graph appears only for one date
这是我的图表的xml:
String[] allStocks = history.split("\n");
String[] singleStock;
ArrayList<DataPoint> points = new ArrayList<>();
GraphView graph = (GraphView) findViewById(R.id.graph);
for(int i=0; i<3; i++)
{
singleStock = allStocks[i].split(",");
Date date = new Date(Long.parseLong(singleStock[0]));
System.out.println(date);
points.add(new DataPoint(new Date(Long.parseLong(singleStock[0])), Float.parseFloat(singleStock[1])));
}
DataPoint[] dbPoint = points.toArray(new DataPoint[points.size()]);
System.out.println(points);
LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(dbPoint);
graph.addSeries(series);
graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(this));
graph.getGridLabelRenderer().setNumHorizontalLabels(2);
// set manual x bounds to have nice steps
graph.getViewport().setXAxisBoundsManual(true);
// as we use dates as labels, the human rounding to nice readable numbers
// is not necessary
graph.getGridLabelRenderer().setHumanRounding(false);
图表中只显示一个日期。当我尝试使用&#39; GraphView&#39;对于日期,一切都按预期工作。如果我的代码中存在任何缺陷,请告诉我。
答案 0 :(得分:0)
之前我没有使用过GraphView,但是我发现的日期示例似乎是将水平标签的数量设置为比绘制的项目数量多一个,所以我会尝试:
graph.getGridLabelRenderer().setNumHorizontalLabels(points.size()+1);