GraphView android:图形的奇怪行为

时间:2013-09-15 15:52:36

标签: android graph android-graphview

我的graphview第一次尝试代码有问题:

GraphView graphView;
GraphViewSeries series;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    GraphViewData[] data = new GraphViewData[4];
    Double[] x_values = new Double[] { 1.0, 2.0, 3.0, 4.0 };
    Double[] y_values = new Double[] { 1.0, 2.0, 3.0, 4.0 };

    for (int i = 0; i < data.length; i++) {
        data[i] = new GraphViewData(x_values[i], y_values[i]);
    }

    series = new GraphViewSeries(data);

    graphView = new LineGraphView(this, "Title");
    graphView.addSeries(series);
    graphView.setScrollable(true);
    graphView.setScalable(true);
    graphView.setBackgroundColor(Color.BLACK);

    LinearLayout l = (LinearLayout) findViewById(R.id.linearLay);
    l.addView(graphView);
}

两个问题: - 背景仍然是白色的 - 放大后,我无法缩小 - x轴上的标签未显示

1 个答案:

答案 0 :(得分:3)

关于白色背景,请尝试添加:

((LineGraphView) graphView).setDrawBackground(true);

您可以设置标签颜色,如下所示:

graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.BLACK);
graphView.getGraphViewStyle().setVerticalLabelsColor(Color.BLACK);

我希望它有效!

BR, 蒂姆