如何在图形中设置背景图像?[英] How to set a background image in graph?

本文是小编为大家收集整理的关于如何在图形中设置背景图像?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在实施与图表相关的一个应用程序.

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

但它仅设置在图中.没有设置总布局.

我的代码是休息.

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

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;    
    }

我将背景设置为布局.

但它没有设置总布局.

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

我有任何一个解决方案请帮助我.

提前感谢.

推荐答案

我可能会在这里出路,但也许您可以使用布局作为图形的容器,并将背景设置为Δt,而是如果没有lectbackground或类似于渲染器.

本文地址:https://www.itbaoku.cn/post/102340.html

问题描述

I am implementing one app related to graphs.

I am trying to set one image as a background of graph.

But it is set only inside of graph.not set total layout.

my code is as fallows.

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

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(true); 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;    
    }

I am setting background to the layout.

But it is not set total layout.

How to set a background image to a graph?

I f any one has solution please help me.

Thanks in advance.

推荐答案

I may be way off here, but maybe you could use a layout as a container for the graph and set the background to that instead if there is no setBackground or similar to the renderer.