当ArrayList中有一个值时,我在aChartEngine中遇到了xlabels的问题。我为折线图生成了自己的XLabels,但是当有一个数据数组值时,在生成的XLabel之上会得到一个不需要的TimeStamp。

我的代码:

private XYMultipleSeriesDataset getDemoDataset() {

        Calendar cal = Calendar.getInstance();
        Date date = new Date();

        date_value = new String[list.size()];
        value_value = new String[list.size()];

        for(int k = 0; k < list.size(); k++){
            date_value[k] = list.get(k).get(DATE);
            value_value[k] = list.get(k).get(VALUE);
        }


        TimeSeries series = new TimeSeries("Line Graph");

        for(int j=0; j < date_value.length; j++) {


                series.add(formatter.stringToDate(date_value[j]), Integer.parseInt());

                }

            XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                 dataset.addSeries(series);
         return dataset;
         }


setChartSetting:

private void setChartSetting(XYMultipleSeriesRenderer renderer){
        renderer.setXRoundedLabels(true);
        renderer.setXTitle("DATES");
        renderer.setYTitle(kpiname);
        renderer.setApplyBackgroundColor(true);
        renderer.setFitLegend(false);
        renderer.setAxesColor(Color.DKGRAY);
        renderer.setShowGrid(true);
        renderer.setZoomEnabled(false);
        renderer.setXLabels(0);
        renderer.setYLabels(10);
        renderer.setZoomEnabled(false, false);
        renderer.setPanEnabled(false, false);





        //String[] date_value = new String[list.size()];
        //String[] value_value = new String[list.size()];

        if(list.isEmpty() || list.size() == 0 || list == null ){
            return;
        }

        if(name.equals(RECOVERED) || name.equals(CONVERSION)){
            largest_size = (int)Double.parseDouble(value_value[0]);
        }else{
               if(!(value_value.length == 0)){
               largest_size = Integer.parseInt(value_value[0]);
              }else{
                  return;
              }
        }

        //used to determine the maximum value for the y-axis
        for(int x =0; x < value_value.length; x++){

                if(Integer.parseInt(value_value[x]) > largest_size){
                    largest_size = Integer.parseInt(value_value[x]);
                }
            }

        renderer.setYAxisMax((double)largest_size);
        renderer.setYAxisMin(0);

        int value_size = value_value.length;
        int m = 0;
        //int add =  value_size/10;
        int add =  largest_size/10;

        /*instance variables for setting the labels on the X-Axis based on weather the values in the array are
         * more than 10 items or less*/


        double d;
        Long l;
        Long l1;
        double d1;

        if(date_value.length <= 1){

          int last = date_value.length;
          int mod = 0;
              //int add_mod = Math.round(last/10);
              int add_mod = (int)Math.round((double)Math.round(last));

                l = Long.valueOf(formatter.stringToDateReport(date_value[0]).getTime());
                d = l.doubleValue();
                   /*tried this to see if i can remove the timestamp*/
                //renderer.addXTextLabel(0.0, "");
                //renderer.removeXTextLabel(0.0);
                //renderer.clearXTextLabels();
                renderer.addXTextLabel(d, date_value[0]);

        }


            else if(date_value.length < 10){


            for(int i = 0; i < date_value.length; i++){

                  if(i >= date_value.length){
                      break;
                  }

            l = Long.valueOf(formatter.stringToDateReport(date_value[i]).getTime());
            d = l.doubleValue();
            renderer.addXTextLabel(d, date_value[i]);

           }

        } else if(date_value.length >= 10){

              int last = date_value.length;
              //int last = 28;
              //Log.d(TAG, "last is " + last);
              int mod = 0;
              //int add_mod = Math.round(last/10);
              int add_mod = (int)Math.round((double)Math.round(last) /10);  // do this to get the decimal value with a double and then round to get nearset whole with int

              for(int i =0; i < date_value.length; i++){

                  if(mod >= date_value.length){
                      break;
                  }


                  l1 = Long.valueOf(formatter.stringToDateReport(date_value[mod]).getTime());
                  d1 = l1.doubleValue();

                  renderer.addXTextLabel(d1, date_value[mod]);
                  mod+=add_mod;
              }
        }

    }
}


接着:

chartView = ChartFactory.getLineChartView(context, getDemoDataset(), setChartSettings(renderer));


当有多个值时,它使用我的自定义XLabels(格式为MMM-yyyy)很好地绘制了图形,但是当ArrayList中只有一个值时,它将生成thats时间戳。

这是一张图片:

最佳答案

确实,这是一个错误。您可以下载包含其功能here的修复程序的版本。

09-04 13:09