Charts: Pie Chart Legends Missing with the dynamically filled data.

I am trying to implement pie chart from ios-charts library everything is working great, however the legends are missing from the graph. The dataPoints and values are supplied dynamically through a for loop image

 for od in chartArray {
        let date = od["Date"] as! NSDate
        let month = formatter.stringFromDate(date)
        if self.dateDict.indexForKey(month) != nil {
            self.dateDict[month]! += 1.0
        }else{
            self.dateDict.updateValue(1.0, forKey: month)
        }
    }


    let dataPointArray = Array(dateDict.keys)
    let valuesArray = Array(dateDict.values)
    setChart(dataPointArray, values: valuesArray)

I have also logged this issue in SO Pie Chart Legends Missing

Request Help for same.

Thanks & Regards

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20 (5 by maintainers)

Most upvoted comments

I have met some issues also related to the order; I always call setData after everything is settled down. Also wondering could this be improved. But we indeed needs to calculate some values that’s related to the chart setting.

Basically I am guessting the problem should be in public func renderLegend or computeLegend when you ‘dynamicly’ set the data.

Each time when you call pieChart.data = yourData, it will invoke notifyDataSetChanged and compute the legends and then redraw the pie chart, so the code looks totally fine to me, and should work no matter ‘static’ or ‘dymaic’ in your case

    public override func notifyDataSetChanged()
    {
        if (_dataNotSet)
        {
            return
        }

        calcMinMax()

        if (_legend !== nil)
        {
            _legendRenderer.computeLegend(_data)
        }

        calculateOffsets()

        setNeedsDisplay()
    }

I am not sure what’s your exact procedure for ‘static’ and ‘dynamic’ way to set the data, you can try dynamicly add the value and see if each time the pie chart is redrawed and renderLegend is called and have your latest legends. You are welcome to debug it.