【问题标题】:MPAndroidChart how to set label color?MPAndroidChart如何设置标签颜色?
【发布时间】:2015-04-22 08:08:22
【问题描述】:

得到以下代码:

    graph = (LineChart) convertView.findViewById(R.id.graph);
    graph.getPaint(Chart.PAINT_LEGEND_LABEL).setColor(Color.BLUE);
    graph.getPaint(Chart.PAINT_YLABEL).setColor(Color.BLUE);
    graph.getPaint(Chart.PAINT_XLABEL).setColor(Color.BLUE);

但 X/Y 值标签的颜色以及图例的标签仍然保持黑色。我错过了什么吗?还有其他方法可以设置这些颜色吗?

例如,这条线有效,并为每个数据点生成蓝色值标签:

    graph.getPaint(Chart.PAINT_VALUES).setColor(Color.BLUE);

提前致谢!

【问题讨论】:

    标签: android mpandroidchart


    【解决方案1】:

    试试这个设置轴和图例的颜色:

    chart.getAxisLeft().setTextColor(...); // left y-axis
    chart.getXAxis().setTextColor(...);
    chart.getLegend().setTextColor(...);
    chart.getDescription().setTextColor(...);
    

    如果您想设置图表内绘制值的颜色,请查看setting colors 文档或setting data 文档。

    【讨论】:

    • 嗨!此解决方案适用于 getXLabels 和 getYLables,但 getLegend() 返回 null。但我可以清楚地看到指示图表颜色的图例和旁边的标签。有什么建议吗?
    • 阅读getLegend方法的文档
    • @PhilippJahoda 有没有办法为每个 x 轴标签设置颜色?这是在这里问的:stackoverflow.com/questions/39772646/…
    • 嗨 Phiip,我在设置为饼图时附加了标签和值,但我想将值的大小增加到粗体。我们可以这样做吗?
    • getLegend() 完成这项工作
    【解决方案2】:

    如果要让饼图聊天更改其标签颜色,您可以这样做

    pieChart.getLegend().setTextColor(Color.WHITE);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多