MPAndroidChart white Background

会有一股神秘感。 提交于 2020-01-05 09:31:15

问题


I am using the MPAndroidChart library. I am setting the multi line chart with data using MPAndroidChart. It's working great but the background is coming white. This is what i am doing

        nhChart = new LineChart(getActivity());
        nhChart.setDescription("Number of Hits View");
        nhChart = (LineChart) hitsView.findViewById(R.id.line_chart_number_of_hits);

        //int color = Color.parseColor("#80101010");
        nhChart.setBackgroundColor(Color.parseColor("#80101010"));
        //nhChart.setBackgroundResource(R.drawable.background_portrate);
        //nhChart.setBackground(getResources().getDrawable(R.drawable.background_portrate));

        nhChart.setStartAtZero(true);   
        nhChart.setDrawBorder(true);

        nhChart.setNoDataTextDescription("No Data available for Charts");

        nhChart.setDrawYValues(false);
        nhChart.setDrawBorder(true);
        nhChart.setScaleEnabled(true);

        nhChart.setHighlightEnabled(false);
        nhChart.setTouchEnabled(true);
        //nhChart.setGridColor(Color.WHITE & 0x70FFFFFF);
        //nhChart.setDragScaleEnabled(true);    
        nhChart.setPinchZoom(true);

        setData(valueDate.size(),10000);
        nhChart.animateX(2500);

        Legend l = nhChart.getLegend();
        l.setForm(LegendForm.CIRCLE);
        l.setFormSize(6f);
        l.setTextColor(Color.WHITE);

        YLabels y = nhChart.getYLabels();
        y.setTextColor(Color.WHITE);
        y.setLabelCount(6);

        XLabels x1 = nhChart.getXLabels();
        x1.setCenterXLabelText(true);
        x1.setPosition(XLabelPosition.BOTTOM);
        x1.setTextColor(Color.WHITE);

I am plotting line graphs in post execute method of AsyncTask in a fragment viewpager. Other fragment showing the graph shows the same white background. I tried setting a color for the background but nothing works. I also left it blank, but its still showing me the white background. I also updated the latest Jar but its not works. Please help. Here is the image how it looks


回答1:


You want this for transparent:

chart.setDrawGridBackground(false);

And this for transparent bar:

chart.setDrawBarShadow(false);



回答2:


Well by default, the backgroud of the chart is transparent which means that it will have whatever color you set for the view/layout below the chart.

If you want to change the background (color, or maybe drawable), you can do that in the following ways:

  • in .xml (android:background="...") --> set the background color of the chart in xml or set the backgroud color of the layout the chart is in.
  • by calling setBackgroundColor(...) or setBackgroundResource(...)

I guess you want your background to be some kind of black? What happens if you call:

chart.setBackgroundColor(Color.BLACK)?

Does setting the background-color work then? Also check the example code in the github repo here. There are some cases in the example app that change the background color.




回答3:


You can do this with:

chart.setBackgroundColor(getResources().getColor(R.color.transparent));

Please define first:

<color name="transparent">#00000000</color>


来源:https://stackoverflow.com/questions/27016811/mpandroidchart-white-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!