Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2890. Turned out it's multiple bar chart but not grouped #2891

Merged
merged 1 commit into from
Oct 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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