簡體   English   中英

使用Graphview在android中繪制圖形?

[英]Draw Graph in android using Graphview?

我想在我的android應用程序上創建一個條形圖。
我需要scrollView上的圖形

我已經嘗試過GraphViewAndroidPlot

UPDATE

GraphView的新更新不支持此方法

使用GraphView:

我在下面創建了一個函數,它將三個數組作為參數。 第一個采用X軸標簽,接下來采用Y軸標簽,最后采用值繪制。

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類:

這個類與文檔中給出的類略有不同。

   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;
    }
}

PS

將此方法稱為:

String[] xAxis = {"RED","WHITE","BLUE","GREEN"};
String[] yAxis = {"GOOD", "AVEGRAGE", "BAD"};
String[] data = {"1", "2", "1","2"};
renderGraph(xAxis, yAxis, data);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM