-
-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2364 from thierryH91200/master
add example playground
- Loading branch information
Showing
14 changed files
with
1,096 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
ChartsDemo-OSX/PlaygroundChart.playground/Pages/BarChart.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// PlayGround | ||
// | ||
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda | ||
// Copyright © 2017 thierry Hentic. | ||
// A port of MPAndroidChart for iOS | ||
// Licensed under Apache License 2.0 | ||
// | ||
// https://github.com/danielgindi/ios-charts | ||
|
||
/*: | ||
**** | ||
[Menu](Menu) | ||
[Previous](@previous) | [Next](@next) | ||
**** | ||
*/ | ||
|
||
//: # Bar Chart | ||
//#-hidden-code | ||
import Cocoa | ||
import Charts | ||
import PlaygroundSupport | ||
//#-end-hidden-code | ||
|
||
|
||
let months = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] | ||
let values : [Double] = [28800, 32400, 36000, 34000, 30000, 42000, 45000] | ||
|
||
let r = CGRect(x: 0, y: 0, width: 600, height: 600) | ||
var chartView = BarChartView(frame: r) | ||
//: ### General | ||
chartView.pinchZoomEnabled = false | ||
chartView.drawBarShadowEnabled = false | ||
chartView.doubleTapToZoomEnabled = false | ||
chartView.drawGridBackgroundEnabled = true | ||
chartView.fitBars = true | ||
//: ### BarChartDataEntry | ||
var yVals = [BarChartDataEntry]() | ||
for i in 0..<7 | ||
{ | ||
yVals.append(BarChartDataEntry(x: Double(i), y: values[i])) | ||
} | ||
//: ### BarChartDataSet | ||
var set1 = BarChartDataSet() | ||
set1 = BarChartDataSet(values: yVals, label: "DataSet") | ||
set1.colors = ChartColorTemplates.vordiplom() | ||
set1.drawValuesEnabled = true | ||
|
||
var dataSets = [ChartDataSet]() | ||
dataSets.append(set1) | ||
//: ### BarChartData | ||
let data = BarChartData(dataSets: dataSets) | ||
chartView.data = data | ||
|
||
chartView.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .easeInBounce) | ||
/*:---*/ | ||
//: ### Setup for the live view | ||
PlaygroundPage.current.liveView = chartView | ||
/*: | ||
**** | ||
[Previous](@previous) | [Next](@next) | ||
*/ |
82 changes: 82 additions & 0 deletions
82
ChartsDemo-OSX/PlaygroundChart.playground/Pages/BubbleChart.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// PlayGround | ||
// | ||
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda | ||
// Copyright © 2017 thierry Hentic. | ||
// A port of MPAndroidChart for iOS | ||
// Licensed under Apache License 2.0 | ||
// | ||
// https://github.com/danielgindi/ios-charts | ||
/*: | ||
**** | ||
[Menu](Menu) | ||
[Previous](@previous) | ||
**** | ||
*/ | ||
|
||
//: # Bubble Chart | ||
import Cocoa | ||
import Charts | ||
import PlaygroundSupport | ||
|
||
let ITEM_COUNT = 20 | ||
|
||
let r = CGRect(x: 0, y: 0, width: 600, height: 600) | ||
var chartView = BubbleChartView(frame: r) | ||
//: ### General | ||
chartView.drawGridBackgroundEnabled = true | ||
//: ### xAxis | ||
let xAxis = chartView.xAxis | ||
xAxis.labelPosition = .bothSided | ||
xAxis.axisMinimum = 0.0 | ||
xAxis.granularity = 1.0 | ||
//: ### LeftAxis | ||
let leftAxis = chartView.leftAxis | ||
leftAxis.drawGridLinesEnabled = true | ||
leftAxis.axisMinimum = 40.0 | ||
//: ### RightAxis | ||
let rightAxis = chartView.rightAxis | ||
rightAxis.drawGridLinesEnabled = true | ||
rightAxis.axisMinimum = 40.0 | ||
//: ### Legend | ||
let legend = chartView.legend | ||
legend.wordWrapEnabled = true | ||
legend.horizontalAlignment = .center | ||
legend.verticalAlignment = .bottom | ||
legend.orientation = .horizontal | ||
legend.drawInside = false | ||
//: ### Description | ||
chartView.chartDescription?.enabled = false | ||
//: ### BubbleChartDataEntry | ||
var entries = [BubbleChartDataEntry]() | ||
for index in 0..<ITEM_COUNT | ||
{ | ||
let y = Double(arc4random_uniform(100)) + 50.0 | ||
let size = (y - 50) / 25.0 | ||
entries.append(BubbleChartDataEntry(x: Double(index) + 0.5, y: y, size: CGFloat(size))) | ||
} | ||
//: ### BubbleChartDataSet | ||
let set = BubbleChartDataSet(values: entries, label: "Bubble DataSet") | ||
set.colors = ChartColorTemplates.vordiplom() | ||
set.valueTextColor = NSUIColor.black | ||
set.valueFont = NSUIFont.systemFont(ofSize: CGFloat(10.0)) | ||
set.drawValuesEnabled = true | ||
set.normalizeSizeEnabled = false | ||
//: ### BubbleChartData | ||
let data = BubbleChartData() | ||
data.addDataSet(set) | ||
chartView.data = data | ||
|
||
chartView.animate(xAxisDuration: 1.0, yAxisDuration: 1.0) | ||
/*:---*/ | ||
//: ### Setup for the live view | ||
PlaygroundPage.current.liveView = chartView | ||
/*: | ||
**** | ||
[Menu](Menu) | ||
[Previous](@previous) | ||
**** | ||
*/ | ||
|
96 changes: 96 additions & 0 deletions
96
ChartsDemo-OSX/PlaygroundChart.playground/Pages/CandleChart.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// PlayGround | ||
// | ||
// Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda | ||
// Copyright © 2017 thierry Hentic. | ||
// A port of MPAndroidChart for iOS | ||
// Licensed under Apache License 2.0 | ||
// | ||
// https://github.com/danielgindi/ios-charts | ||
/*: | ||
**** | ||
[Menu](Menu) | ||
[Previous](@previous) | [Next](@next) | ||
**** | ||
*/ | ||
|
||
//: # Candle Chart | ||
import Cocoa | ||
import Charts | ||
import PlaygroundSupport | ||
|
||
|
||
func randomFloatBetween(from: Float, to: Float)->Float | ||
{ | ||
return Float(arc4random_uniform( UInt32(to - from ))) + Float(from) | ||
} | ||
|
||
|
||
let ITEM_COUNT = 20 | ||
|
||
|
||
let r = CGRect(x: 0, y: 0, width: 600, height: 600) | ||
var chartView = CandleStickChartView(frame: r) | ||
//: ### General | ||
chartView.drawGridBackgroundEnabled = true | ||
//: ### xAxis | ||
let xAxis = chartView.xAxis | ||
xAxis.labelPosition = .bothSided | ||
xAxis.axisMinimum = 0.0 | ||
xAxis.granularity = 1.0 | ||
//: ### LeftAxis | ||
let leftAxis = chartView.leftAxis | ||
leftAxis.drawGridLinesEnabled = true | ||
leftAxis.axisMinimum = 0.0 | ||
//: ### RightAxis | ||
let rightAxis = chartView.rightAxis | ||
rightAxis.drawGridLinesEnabled = true | ||
rightAxis.axisMinimum = 0.0 | ||
//: ### Legend | ||
let legend = chartView.legend | ||
legend.wordWrapEnabled = true | ||
legend.horizontalAlignment = .center | ||
legend.verticalAlignment = .bottom | ||
legend.orientation = .horizontal | ||
legend.drawInside = false | ||
//: ### Description | ||
chartView.chartDescription?.enabled = false | ||
//: ### CandleChartDataEntry | ||
var entries = [CandleChartDataEntry]() | ||
|
||
for i in 0..<ITEM_COUNT | ||
{ | ||
let mult: Float = 50 | ||
let val = randomFloatBetween(from: mult, to: mult + 40) | ||
let high = randomFloatBetween(from: 8, to: 17) | ||
let low: Float = randomFloatBetween(from: 8, to: 17) | ||
let open: Float = randomFloatBetween(from: 1, to: 7) | ||
let close: Float = randomFloatBetween(from: 1, to: 7) | ||
let even: Bool = i % 2 == 0 | ||
|
||
entries.append(CandleChartDataEntry(x: Double(i), shadowH: Double(val + high), shadowL: Double(val - low), open: Double(even ? val + open : val - open), close: Double(even ? val - close : val + close))) | ||
} | ||
//: ### CandleChartDataSet | ||
let set = CandleChartDataSet(values: entries, label: "Candle DataSet") | ||
set.colors = [#colorLiteral(red: 0.313725490196078, green: 0.313725490196078, blue: 0.313725490196078, alpha: 1.0)] | ||
|
||
set.decreasingColor = #colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1) | ||
set.shadowColor = NSColor.red | ||
set.valueFont = NSUIFont.systemFont(ofSize: CGFloat(10.0)) | ||
set.drawValuesEnabled = true | ||
set.shadowWidth = 0.7 | ||
//: ### CandleChartData | ||
let data = CandleChartData() | ||
data.addDataSet(set) | ||
chartView.data = data | ||
chartView.animate(xAxisDuration: 1.0, yAxisDuration: 1.0) | ||
/*:---*/ | ||
//: ### Setup for the live view | ||
PlaygroundPage.current.liveView = chartView | ||
/*: | ||
**** | ||
[Previous](@previous) | [Next](@next) | ||
*/ | ||
|
||
|
Oops, something went wrong.