【问题标题】:MPAndroidChart white BackgroundMPAndroidChart 白色背景
【发布时间】:2014-11-19 12:26:19
【问题描述】:

我正在使用MPAndroidChart 库。我正在使用 MPAndroidChart 设置带有数据的多折线图。它工作得很好,但背景变白了。这就是我正在做的事情

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

我在片段查看器中的 AsyncTask 的后执行方法中绘制折线图。显示图表的其他片段显示相同的白色背景。我尝试为背景设置颜色,但没有任何效果。我也将其留空,但它仍然向我显示白色背景。我还更新了最新的 Jar,但它不起作用。请帮忙。 这是图像的外观

【问题讨论】:

    标签: android background mpandroidchart


    【解决方案1】:

    你希望这个透明:

    chart.setDrawGridBackground(false);
    

    这对于透明条:

    chart.setDrawBarShadow(false);
    

    【讨论】:

    • 如何在左侧添加x轴描述(底部)和y轴描述?你能帮我解决这个问题吗?
    【解决方案2】:

    默认情况下,图表的背景是透明,这意味着它将具有您为图表下方的视图/布局设置的任何颜色。

    如果您想更改背景(颜色,或者可能是可绘制的),您可以通过以下方式进行:

    • 在 .xml (android:background="...") --> 在xml中设置图表的背景颜色或设置图表所在布局的背景颜色。
    • 致电setBackgroundColor(...)setBackgroundResource(...)

    我猜你希望你的背景是某种黑色? 如果你打电话会发生什么:

    chart.setBackgroundColor(Color.BLACK)?

    那么设置背景颜色是否有效?还要检查 github repo here 中的示例代码。示例应用中的某些情况会更改背景颜色。

    【讨论】:

    • 嗨菲利普,感谢您的回复。我已经尝试了您提到的所有内容,并尝试按照 repo 中提到的方式实施,但我仍然得到白色背景。这有点奇怪,但我得到了条形图和雷达图的欲望背景,但使用折线图仅显示带有渐变的白色背景。我本可以发布图片,但由于我的声誉很低,我不能这样做。
    • 对我不起作用。无论我尝试什么,我都会得到一些暗灰色的图表。它绝对不透明。
    【解决方案3】:

    你可以这样做:

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

    请先定义:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多