Search code examples
javaandroidandroid-graphview

incorrect display GraphView(android)


Sorry for my English. I do not know why I did not properly displays a message GraphView. Now in the graph below displays constantly 1,1,1,1 ... Though would have 1,2,3,4 ...And evaluation are all 1. A shows the graph as 10. Why is it, tell me please.

enter image description here

GraphViewSeriesStyle seriesStyle = new GraphViewSeriesStyle();

         BarGraphView graphView = new BarGraphView(this, "test");

         //Our vertical graph
         graphView.setVerticalLabels(new String[] { "10", "9", "8", "7", "6",
                    "5", "4", "3", "2", "1" });

         //listMarks its ArrayList whith Marks
         String[] array = new String[ listMarks.size() ];

         //add marks in array
         for(int i = 0; i < listMarks.size(); i++) {
             array[i] = "1";
         }

        graphView.setHorizontalLabels(array); 

         seriesStyle.setValueDependentColor(new ValueDependentColor() {
             @Override
             public int get(GraphViewDataInterface data) {
                  return Color.rgb((int)(22+((data.getY()/3))), (int)(160-((data.getY()/3))), (int)(134-((data.getY()/3))));
             }
         });


        GraphViewData[] data = new GraphViewData[array.length];

        for (int a = 0; a < array.length; a++) {
            data[a] = new GraphView.GraphViewData(a, Double.parseDouble(array[a]));
        }

        GraphViewSeries series = new GraphViewSeries("aaa", seriesStyle, data);

        graphView.setManualYMinBound(0);
        graphView.addSeries(series);
        LinearLayout layout = (LinearLayout) findViewById(R.id.subLayout);
        layout.addView(graphView);

Solution

  • Change:

    array[i] = "1";
    

    to:

    array[i] = ""+i;
    

    in the following loop"

    //add marks in array
             for(int i = 0; i < listMarks.size(); i++) {
                 array[i] = "1";
             }