本文介绍了使用Graphview在Android的绘制图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要创建我的Android应用程序吧图表。
我需要图表上的滚动视图
I want to create a bars graph on my android application.
I need the graph on a scrollView.
我已经试过已经 GraphView 和的。
推荐答案
使用GraphView:
我做了下面一个函数具有三个数组作为参数。第一个就是X轴标签,下一个需要的Y轴标签和最后一个取值要绘制。
I have made a function below that takes three arrays as parameter. First one takes X-axis labels, next takes Y-axis labels and last takes values to be plotted.
code
private void renderGraph(String[] xAxis, String[] yAxis, float[] data) {
GraphViewData[] data = new GraphViewData[xAxis.length];//this class is defined below
double v = 1, w = 1;
int num = xAxis.length;
for (int j = 0; j < num; j++) {
v = data[j];
data[j] = new GraphViewData(j, v);
}
GraphViewSeries example1 = new GraphViewSeries(data);
GraphView graphView = new BarGraphView(this, "GRAPH TITLE");
graphView.setVerticalLabels(yAxis);
graphView.setHorizontalLabels(xAxis);
graphView.addSeries(example1);
example1.getStyle().color = Color.BLUE;
graphView.setScalable(true);
graphView.getGraphViewStyle().setTextSize(18);
graphView.setScrollable(false);
graphView.getGraphViewStyle().setGridColor(Color.DKGRAY);
graphView.getGraphViewStyle().setGridStyle(GridStyle.VERTICAL);
graphView.getGraphViewStyle().setNumHorizontalLabels(5);
LinearLayout layout = (LinearLayout) findViewById(R.id.graphz);//graphz is defined in layout
layout.addView(graphView);
}
GraphViewData类:
这个类是从一个文档中给出点点的变体。
This class is little bit variant from the one given in documentation.
public class GraphViewData implements GraphViewDataInterface {
private double x, y;
public GraphViewData(double x, double y) {
super();
this.x = x;
this.y = y;
}
@Override
public double getX() {
// TODO Auto-generated method stub
return this.x;
}
@Override
public double getY() {
// TODO Auto-generated method stub
return this.y;
}
}
P.S。
调用此方法为:
String[] xAxis = {"RED","WHITE","BLUE","GREEN"};
String[] yAxis = {"GOOD", "AVEGRAGE", "BAD"};
String[] data = {"1", "2", "1","2"};
renderGraph(xAxis, yAxis, data);
更新
新的更新到GraphView不支持这种做法
这篇关于使用Graphview在Android的绘制图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!