我正在使用MPAndroidChart库来绘制BarChart,我使用3种颜色来绘制条形图,基于条形值。
我想显示解释每种颜色(即图例)的文字,如下图所示。
在示例图片中,我想要的文字是“公司A”,“公司B”,“公司C”。
答案 0 :(得分:1)
您可以使用setCustom()
。
Legend l = mChart.getLegend();
l.setCustum(colorArray, labelArray);
/**
* Sets a custom legend's labels and colors arrays. The colors count should
* match the labels count. * Each color is for the form drawn at the same
* index. * A null label will start a group. * A ColorTemplate.COLOR_SKIP
* color will avoid drawing a form This will disable the feature that
* automatically calculates the legend labels and colors from the datasets.
* Call resetCustom() to re-enable automatic calculation (and then
* notifyDataSetChanged() is needed to auto-calculate the legend again)
*/