0
votes

I'm trying to use a bar chart to show my data. I want to show things grouped by date, and for each date I have 7 people and their associated value.

I created a tubular CPTBarPlot for each date with a barWidth of 0.25

I'm confused as to what to set the barOffset to for each plot so things draw properly.

For the storage of data, I used var plotData: [NSDate : [Double]]?. That array of double has exactly 7 values for each NSDate (one for each person, in order)

The numberForPlot method I have is drawing all the values, but the grouping seems to be by person instead of date, and they're drawing over each other. This is what I used:

func numberForPlot(plot: CPTPlot, field fieldEnum: UInt, recordIndex idx: UInt) -> AnyObject? {
    guard let type = CPTBarPlotField(rawValue: Int(fieldEnum)) else { return nil }

    switch type {
    case .BarBase:
        fatalError()

    case .BarLocation:
        return idx

    case .BarTip:
        guard let date = plot.identifier as? NSDate, values = plotData?[date] else {
            fatalError()
        }

        return values[Int(idx)]
    }
}
1
How many bar plots do you have? One for each date or seven (one for each person)? From the description of the problem, having one plot for each person makes more sense. - Eric Skroch
OK, I swapped things around based on your comment. Now plotData is keyed by name instead of date, so I have a plot per person. The first two plots though from the second date forward are covered by other people though. So instead of seeing 7 plots, some space, 7 plots, etc... I see a continuous stream of plots. - Gargoyle

1 Answers

0
votes

The bars for each plot are 0.25 unit wide and one unit apart. Since you have seven plots, they are going to overlap unless you decrease the bar width. I would suggest using offsets of -0.3, -0.2, -0.1, 0.0, 0.1, 0.2, and 0.3. This will leave a small space between the sets of bars to set the groups apart. Use a bar width of 0.1 on each plot if you don't want any overlap.