如何在图表中设置背景图像?

时间:2012-04-07 11:49:55

标签: android

我正在实施一个与图表相关的应用。

我正在尝试将一个图像设置为图形背景。

但它只在图形内部设置。未设置总布局。

我的代码就像休耕一样。

............................................... .............

layout =(LinearLayout)findViewById(R.id.linearLayout1);

        XYMultipleSeriesRenderer renderer = getBarDemoRenderer();
        setChartSettings(renderer, "Call Duration/Incoming", "my chart", "", 0.5, 12.5,
                0, 60, 0, Color.LTGRAY);
        mChartView = ChartFactory.getBarChartView(BarchartExampleActivity.this, getBarDemoDataset(renderer), renderer, Type.STACKED);
        layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));


}
public XYMultipleSeriesRenderer getBarDemoRenderer() 
{

      XYMultipleSeriesRenderer renderer = buildBarRenderer();
        renderer.setBarSpacing(0.5);
        renderer.setXLabels(0);
        renderer.setYLabels(10);
        renderer.addXTextLabel(1, "1");
        renderer.addXTextLabel(2, "2");
        renderer.addXTextLabel(3, "3");
        renderer.addXTextLabel(4, "4");
        renderer.addXTextLabel(5, "5");
        renderer.addXTextLabel(6, "6");
        renderer.addXTextLabel(7, "7");
        renderer.addXTextLabel(8, "8");
        renderer.addXTextLabel(9, "9");
        renderer.addXTextLabel(10, "10");













        renderer.setYLabelsAlign(Align.RIGHT);

        SimpleSeriesRenderer r = renderer.getSeriesRendererAt(0);

// r.setDisplayChartValues(true);             r.setChartValuesTextSize(12);             r.setChartValuesSpacing(7);             r.setGradientEnabled(真);             r.setGradientStart(0,Color.BLUE);             r.setGradientStop(20,Color.GREEN);

        return renderer;

}
 protected XYMultipleSeriesRenderer buildBarRenderer() 
  {
      Log.v("abstract","bbb");
    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    renderer.setAxisTitleTextSize(16);
    renderer.setChartTitleTextSize(20);
    renderer.setLabelsTextSize(15);
    renderer.setLegendTextSize(15);


    for (int i = 0; i < 1; i++) 
    {
      SimpleSeriesRenderer r = new SimpleSeriesRenderer();

      renderer.addSeriesRenderer(r);
    }
    return renderer;
  }
 protected void setChartSettings(XYMultipleSeriesRenderer renderer, String title, String xTitle,
          String yTitle, double xMin, double xMax, double yMin, double yMax, int axesColor,
          int labelsColor) 
      {
          Log.v("abstract","555"+title  +xMin   +yMin);
          renderer.setShowLegend(false);
        renderer.setChartTitle(title);
        renderer.setXTitle(xTitle);
        renderer.setYTitle(yTitle);
        renderer.setXAxisMin(xMin);
        renderer.setXAxisMax(xMax);
        renderer.setYAxisMin(yMin);
        renderer.setYAxisMax(yMax);
        renderer.setShowGrid(true);



      }
 private XYMultipleSeriesDataset getBarDemoDataset(XYMultipleSeriesRenderer renderer) 
    {
     double[] minValues = new double[]    {0, 0, 0,0,  0,0,  0,0,  0,0,  0,0, 0};
        double[] maxValues = new double[] { 7,0,10,0, 24,0, 30,0, 35,0, 40, 0,45};

        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        RangeCategorySeries series = new RangeCategorySeries("");
        int length = minValues.length;
        for (int k = 0; k < length; k++) 
        {
         series.add(minValues[k], maxValues[k]);
        }
        dataset.addSeries(series.toXYSeries());
        return dataset;    
    }

我正在为布局设置背景。

但它没有设置总布局。

如何将背景图像设置为图形?

我有任何人有解决方案请帮助我。

提前致谢。

1 个答案:

答案 0 :(得分:1)

我可能会离开这里,但也许您可以使用布局作为图形的容器,如果没有setBackground或类似于渲染器,则将背景设置为该。