【问题标题】:Swift danielgindi/Charts Pie Chart Legend LabelsSwift danielgindi/Charts 饼图图例标签
【发布时间】:2020-03-13 07:11:41
【问题描述】:

在为饼图绘制图例时,我没有显示所有标签。

这里是代码;

func AllocationsChart( pieChart: PieChartView ) {

    let entry1 = PieChartDataEntry(value: 65, label: "Stock")
    let entry2 = PieChartDataEntry(value: 35, label: "Bond")

    let dataSet = PieChartDataSet(entries: [entry1, entry2 ] , label: "Allocation" )
    let data = PieChartData(dataSet: dataSet)

    pieChart.data = data

    let labels = ["Stock","Bonds"]   // would like to set the label here

    let colors = [ Color.stock,  Color.bond ]
    dataSet.colors =  colors
    dataSet.sliceSpace = 2

    pieChart.drawHoleEnabled = true
    pieChart.transparentCircleColor = .white
    pieChart.holeRadiusPercent = 0.6667

    let l = pieChart.legend
    l.enabled = true
    l.orientation = .vertical
    l.form = .circle

}

这是结果。

是否可以像我们对其他图表视图一样设置标签:

 xAxis.valueFormatter = IndexAxisValueFormatter(values: labels)

首先,为什么债券条目没有显示?

图例标签的颜色也与条目不匹配。

非常感谢。

【问题讨论】:

    标签: swift charts


    【解决方案1】:

    就是在最后加上这行代码:

    pieChart.notifyDataSetChanged()
    

    仍然不知道如何设置 PieChartDataEntry 标签以外的标签?

    祝你好运。

    【讨论】:

      【解决方案2】:

      将 label 语句更改为 label: "nil" 并查看它显示的内容。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-28
        • 1970-01-01
        • 2023-04-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-08
        • 2016-05-14
        相关资源
        最近更新 更多