Android GraphView条形图多个系列

时间:2014-12-22 10:32:31

标签: android android-graphview

嗨我有一个使用android GraphView的条形图。有3个系列,我需要传递给它,但它目前正在绘制所有3个系列彼此是有一种方法来改变条的宽度,以便它显示

继承人我有什么安慰

try{
                    JSONArray graphArray = returnGraphyArray(statistics);
                    if(graphArray != null){
                        int graphLength = graphArray.length();
                        GraphViewData[] calls = new GraphViewData[graphLength];
                        GraphViewData[] length = new GraphViewData[graphLength];
                        GraphViewData[] transfered = new GraphViewData[graphLength];

                        for(int r = 0; r < graphLength; r++){
                            JSONObject row = graphArray.getJSONObject(r);
                            calls[r] = new GraphViewData(r,Integer.parseInt(row.getJSONObject("data").getString("total_calls")));
                            length[r] = new GraphViewData(r,Integer.parseInt(row.getJSONObject("data").getString("avg_call_length"))/60);
                            transfered[r] = new GraphViewData(r,Integer.parseInt(row.getJSONObject("data").getString("calls_transferred")));
                        } 

                        GraphViewSeries totalCallsSeries = new GraphViewSeries( "Total Calls", new GraphViewSeriesStyle(getResources().getColor(R.color.pink), 5),calls);
                        GraphViewSeries totalCallLengthSeries = new GraphViewSeries( "Total Call Length", new GraphViewSeriesStyle(getResources().getColor(R.color.green), 5),length);
                        GraphViewSeries totalCallsTransSeries = new GraphViewSeries( "Calls Transfered", new GraphViewSeriesStyle(getResources().getColor(R.color.blue), 5),transfered);

                        BarGraphView graphView = new BarGraphView(context, "");
                        graphView.addSeries(totalCallLengthSeries); 
                        graphView.addSeries(totalCallsTransSeries); 
                        graphView.addSeries(totalCallsSeries); // data
                        graphView.setHorizontalLabels(bottomlabels);
                        graphView.setShowLegend(false);
                        graphView.setLegendAlign(LegendAlign.TOP);
                        graphView.setLegendWidth(SM_Global.pxFromDp(context, 100));
                        graphView.getGraphViewStyle().setNumHorizontalLabels(6);
                        layout.addView(graphView);  
                    }else{
                        layout.setVisibility(View.GONE);
                        ImageView legend = (ImageView)v.findViewById(R.id.graph_legend);
                        legend.setVisibility(View.GONE);
                    }

1 个答案:

答案 0 :(得分:0)

根据GraphView网站: &#34;注意:目前无法绘制多个条形图。更详细地说:它是可能的,但是条形图将在相同的位置呈现,因此它们将重叠。&#34;

我建议改用AChartEngine。这是jar文件的链接 https://code.google.com/p/achartengine/downloads/list

这是一个例子 http://wptrafficanalyzer.in/blog/android-drawing-bar-chart-using-achartengine/