Brandon
Brandon

Reputation: 23485

CorePlot vertical scrolling for horizontal bars

I'm using core plot to graph a bunch of data with the ranges:

X: 0 to 200 Y: 0 to 35

I've made my bar graph render Horizontally but it will not scroll.

I have:

func setupSpace() {
    let plot = CPTBarPlot()
    plot.barsAreHorizontal = true
    plot.delegate = self
    plot.dataSource = self
    plot.barCornerRadius = 5.0
    plot.barWidth = 2.0
    plot.barOffset = 1.0
    self.hostedGraph?.addPlot(plot)
}

func reloadData() {
    let xMin = 0.0
    let yMin = 0.0
    let xMax = 200
    let yMax = 35.0

    let plotSpace = self.hostedGraph?.defaultPlotSpace as! CPTXYPlotSpace

    plotSpace.xRange = CPTPlotRange(locationDecimal: CPTDecimalFromDouble(xMin), lengthDecimal: CPTDecimalFromDouble(xMax - xMin))
    plotSpace.globalXRange = CPTPlotRange(locationDecimal: CPTDecimalFromDouble(xMin), lengthDecimal: CPTDecimalFromDouble(xMax - xMin))

    plotSpace.yRange = CPTPlotRange(locationDecimal: CPTDecimalFromDouble(yMax), lengthDecimal: CPTDecimalFromDouble(-(yMax - yMin) - 1))
    plotSpace.globalYRange = CPTPlotRange(locationDecimal: CPTDecimalFromDouble(yMax), lengthDecimal: CPTDecimalFromDouble(-(yMax - yMin) - 1))

    self.hostedGraph?.reloadData()
}

But my bars draw like:

enter image description here

I need them to draw without overlapping and I need them to be able to scroll in the vertical direction.

How can I do this?

Upvotes: 0

Views: 190

Answers (1)

Eric Skroch
Eric Skroch

Reputation: 27381

Reduce the length of the yRange to only show some of the bars in the visible plot area. You will be able to scroll to see the other bars.

Upvotes: 1

Related Questions