achart引擎设置

时间:2012-02-02 03:48:36

标签: android achartengine

我试过使用achart引擎,但文档有点不清楚。我也尝试过查看这些例子。

有人可以解释如何增加附加条形图中线条的粗细吗?此外,我想将每个栏分成它自己的系列,但我没有运气这样做(我的代码在图像下面)。很长一段时间我一直在研究这个问题!

enter image description here

public XYMultipleSeriesRenderer getBarDemoRenderer() {
     Log.d(LOG_TAG, "Entering getBarDemoRenderer");
     XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();   
     renderer.setAxisTitleTextSize(18);
     renderer.setChartTitleTextSize(20);
     renderer.setLabelsTextSize(18);
     renderer.setLegendTextSize(14);
     renderer.setMargins(new int[] {20, 30, 15, 0});
     int[] color = {Color.RED, Color.CYAN,Color.YELLOW, Color.LTGRAY,Color.MAGENTA, Color.GREEN, Color.WHITE};

     for(int i=0; i<7; i++){
         SimpleSeriesRenderer r = new SimpleSeriesRenderer();
         r.setColor(color[i]);
         renderer.addSeriesRenderer(r);  
     }

     int renderCount = renderer.getSeriesRendererCount();
     Log.d(LOG_TAG, "Renderer series count =  " + renderCount);

     return renderer;
 }

 private XYMultipleSeriesDataset getApplianceDataset() {

     XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();

     try{

         CategorySeries series = null;
         for (Map.Entry<String,Float> entry : list.entrySet()) {
             String key = entry.getKey();
             series = new CategorySeries (key);
             String b=String.valueOf(entry.getValue());
             double value=Double.valueOf(b);
             series.add(value);   
             dataset.addSeries(series.toXYSeries());
         }

     }catch(IllegalArgumentException e){
         Log.e(LOG_TAG, "IllegalArgumentException " + e.toString());
         Toast.makeText(this, "Unable to show chart", Toast.LENGTH_LONG).show();
     }

     int dataSeriesCount = dataset.getSeriesCount();
     return dataset;
 }


    private void setChartSettings(XYMultipleSeriesRenderer renderer) {         
        renderer.setChartTitle("Test Bar Chart");
        renderer.setChartTitleTextSize(20);
        renderer.setXTitle("Appliance");
        renderer.setYTitle("Watt Hours (wh)");
        renderer.setXAxisMax(3);
        renderer.setXAxisMin(0.0);
        renderer.setYAxisMax(1800);
        renderer.setYAxisMin(0);   
    }

1 个答案:

答案 0 :(得分:0)

在setChartSettings中给出

        renderer.setBarSpacing(1.0f);
        renderer.setMargins(new int[] {10, 10, 10, 0});