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

add example playground #2364

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
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
32 changes: 2 additions & 30 deletions ChartsDemo-OSX/ChartsDemo-OSX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,6 @@
remoteGlobalIDString = 06165F2E1D8110E600722320;
remoteInfo = ChartsTests;
};
0630AE741D812840008859B0 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0630AE691D812840008859B0 /* Charts.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 06B120D51D811E6200D14B02;
remoteInfo = ChartsRealm;
};
0630AE761D812840008859B0 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0630AE691D812840008859B0 /* Charts.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 06B120FF1D811F1600D14B02;
remoteInfo = ChartsRealmTests;
};
0630AE8E1D8128A5008859B0 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 0630AE691D812840008859B0 /* Charts.xcodeproj */;
Expand All @@ -71,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 @@ -100,8 +87,6 @@
children = (
0630AE711D812840008859B0 /* Charts.framework */,
0630AE731D812840008859B0 /* ChartsTests.xctest */,
0630AE751D812840008859B0 /* ChartsRealm.framework */,
0630AE771D812840008859B0 /* ChartsRealmTests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -122,6 +107,7 @@
children = (
65B3F6401C73B4F5000983D0 /* ChartsDemo-OSX */,
65B3F63F1C73B4F5000983D0 /* Products */,
03780C7E1EA29C87005C11C8 /* PlaygroundChart.playground */,
0630AE691D812840008859B0 /* Charts.xcodeproj */,
);
sourceTree = "<group>";
Expand Down Expand Up @@ -223,20 +209,6 @@
remoteRef = 0630AE721D812840008859B0 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
0630AE751D812840008859B0 /* ChartsRealm.framework */ = {
isa = PBXReferenceProxy;
fileType = wrapper.framework;
path = ChartsRealm.framework;
remoteRef = 0630AE741D812840008859B0 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
0630AE771D812840008859B0 /* ChartsRealmTests.xctest */ = {
isa = PBXReferenceProxy;
fileType = wrapper.cfbundle;
path = ChartsRealmTests.xctest;
remoteRef = 0630AE761D812840008859B0 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
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