0

I have an app that displays line chart data, and each line can be hidden or shown. How can I reset the chart boundaries when a line is hidden / shown?

This is the code I'm using to hide each line:

    let lineIndex = sender.checkedValue! as! Int
    print(lineIndex)
    let line = self.chart.data?.dataSets[lineIndex]
    if sender.checkState == .checked {
        line?.visible = true
        line?.highlightEnabled = true
    } else {
        line?.visible = false
        line?.highlightEnabled = false
    }
    line?.notifyDataSetChanged()
    self.chart.leftAxis.resetCustomAxisMax()
    self.chart.leftAxis.resetCustomAxisMin() // not working
    self.chart.data?.notifyDataChanged()
    self.chart.notifyDataSetChanged()

How can I reset the line? I have a .first and .last property index for each line, do I need to do it manually?

enter image description here This graph should be resized to fit the data when the line is hidden, and also when data is shown again. d

Community
  • 1
  • 1
Peter S
  • 827
  • 1
  • 8
  • 24

1 Answers1

0

if you don't need it, you should delete the data set. It is used to calculate the range. hiding is just "hiding", not ignoring.

Wingzero
  • 9,644
  • 10
  • 39
  • 80