swiftgraphviewcontrollercore-plot

Does CorePlot have away to disconnect a graph if the delta between two close data points is too high?


I am trying to create a visual pause between strands of data on my graph, for that I need the graph to be able to break for some duration and then comeback.

It is a running graph, so I cannot specify the exact places where the graph will break, however, it supposed to break whenever the value of the data point reaches 0 at any Index.

This is how I setup my plots:

   notePlot = CPTScatterPlot()
    let notePlotLineStile = CPTMutableLineStyle()
    notePlotLineStile.lineJoin = .round
    notePlotLineStile.lineCap = .round
    notePlotLineStile.lineWidth = 6
    notePlotLineStile.lineColor = CPTColor.orange()
    notePlot.dataLineStyle = notePlotLineStile
    notePlot.curvedInterpolationOption = .catmullCustomAlpha
    notePlot.interpolation = .curved
    notePlot.identifier = "trueNote" as NSCoding & NSCopying & NSObjectProtocol
    notePlot.dataSource = (self as CPTPlotDataSource)
    notePlot.delegate = (self as CALayerDelegate)x
    graph.add(notePlot, to: graph.defaultPlotSpace)

The data is represented by an array of doubles.

I have came up with two potential solutions, but can't find any tools in CorePlot that would address: delete all of the data points, which value is set to zero. But CorePlot only has deleteByIndex, so I need a way to get the indexes of all points which values are 0. Or break off the graph whenever the delta between two points is too high using the graph style options, however, that option does not exist. I provided the examples of what it looks like and should look like below:

should

looks like right now


Solution

  • To get a break in the plot line, return nil instead of zero (0) from the datasource. Don't try to delete the data point—that will connect the plot line across the gap.