Skip to content

Commit

Permalink
Merge pull request #2891 from liuxuan30/2890
Browse files Browse the repository at this point in the history
fix #2890. Turned out it's multiple bar chart but not grouped
  • Loading branch information
liuxuan30 committed Oct 17, 2017
2 parents 8245f32 + 655d0be commit 130d026
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ChartsDemo-OSX/ChartsDemo-OSX/Demos/BarDemoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ open class BarDemoViewController: NSViewController
super.viewDidLoad()

// Do any additional setup after loading the view.
let ys1 = Array(1..<10).map { x in return sin(Double(x) / 2.0 / 3.141 * 1.5) }
let ys2 = Array(1..<10).map { x in return cos(Double(x) / 2.0 / 3.141) }
let xArray = Array(1..<10)
let ys1 = xArray.map { x in return sin(Double(x) / 2.0 / 3.141 * 1.5) }
let ys2 = xArray.map { x in return cos(Double(x) / 2.0 / 3.141) }

let yse1 = ys1.enumerated().map { x, y in return BarChartDataEntry(x: Double(x), y: y) }
let yse2 = ys2.enumerated().map { x, y in return BarChartDataEntry(x: Double(x), y: y) }
Expand All @@ -31,10 +32,21 @@ open class BarDemoViewController: NSViewController
let ds1 = BarChartDataSet(values: yse1, label: "Hello")
ds1.colors = [NSUIColor.red]
data.addDataSet(ds1)

let ds2 = BarChartDataSet(values: yse2, label: "World")
ds2.colors = [NSUIColor.blue]
data.addDataSet(ds2)

let barWidth = 0.4
let barSpace = 0.05
let groupSpace = 0.1

data.barWidth = barWidth
self.barChartView.xAxis.axisMinimum = Double(xArray[0])
self.barChartView.xAxis.axisMaximum = Double(xArray[0]) + data.groupWidth(groupSpace: groupSpace, barSpace: barSpace) * Double(xArray.count)
// (0.4 + 0.05) * 2 (data set count) + 0.1 = 1
data.groupBars(fromX: Double(xArray[0]), groupSpace: groupSpace, barSpace: barSpace)

self.barChartView.data = data

self.barChartView.gridBackgroundColor = NSUIColor.white
Expand Down

0 comments on commit 130d026

Please sign in to comment.