Skip to content

Commit

Permalink
Merge pull request #2364 from thierryH91200/master
Browse files Browse the repository at this point in the history
add example playground
  • Loading branch information
pmairoldi committed Sep 25, 2017
2 parents 2ccd171 + 8cbdf6d commit 8245f32
Show file tree
Hide file tree
Showing 14 changed files with 1,096 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChartsDemo-OSX/ChartsDemo-OSX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
03780C7E1EA29C87005C11C8 /* PlaygroundChart.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = PlaygroundChart.playground; sourceTree = "<group>"; };
0630AE691D812840008859B0 /* Charts.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Charts.xcodeproj; path = ../Charts.xcodeproj; sourceTree = "<group>"; };
5B9A0C391C83AB1800ED8ED8 /* BarDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarDemoViewController.swift; sourceTree = "<group>"; };
5B9A0C3B1C83AB2100ED8ED8 /* LineDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LineDemoViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -106,6 +107,7 @@
children = (
65B3F6401C73B4F5000983D0 /* ChartsDemo-OSX */,
65B3F63F1C73B4F5000983D0 /* Products */,
03780C7E1EA29C87005C11C8 /* PlaygroundChart.playground */,
0630AE691D812840008859B0 /* Charts.xcodeproj */,
);
sourceTree = "<group>";
Expand Down
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)
*/
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)
****
*/

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)
*/


Loading

0 comments on commit 8245f32

Please sign in to comment.