ivnsch / swiftcharts Goto Github PK
View Code? Open in Web Editor NEWEasy to use and highly customizable charts library for iOS
License: Apache License 2.0
Easy to use and highly customizable charts library for iOS
License: Apache License 2.0
I have this error after i update to xcode 7.1
Help me pls.
How soon is "coming soon" for the documentation? Just in line comments in the examples would help. Having a terrible time getting the views sized correctly. In the examples you're moving the view down by 70px why? Using almost identical code my bar chart is squished into about 100px height. Its hard to figure out why without some documentation
Hi, thanks for making swiftcharts: it's awesome..I'm a beginner SWIFT 2 programmer and am trying out the basic chart example. How do I prevent the animation of bars every time the chart loads?
Is it possible to set the y axes labels all double/int values but the x axes labels all string values in LineChart?
Assume that I have arrays of values like:
line1: [1.1, 2.5, 1.3, 8.4, 2.2]
line2: [4.8, 5.1, 0.6, 7.2, 9.1]
axisX: [A,B,C,D,E]
and I'd like my chart looks this way: (sorry for the ugly presenting)
The chartPoints for LineChart seems need to be in (x,y) format, which is a little trivial for combining two elements in different values array into one pair (e.g. (line1[0], axisX[0]) ), and I see no text parameter in the chartPoints class.
Do I have to use Chart class for more flexible layer settings to accomplish this or is there a simpler way within the LineChart?
Thanks for supporting!
I would like to link two touch events to each point in the scatter plot as follows:
I am unsure how to integrate this with my extension of the Bubble Chart (gist --> https://gist.github.com/0a5191ece2b870b33658.git).
The commented code, excluding that in the header, shows my attempts to create a response to a long gesture by the user. If I put performSegueWithIdentifier
in bubblesLayer
, then the segue happens when the bubble layer is rendered. Putting performSegueWithIdentifier
in the inner code block of bubblesLayer
that creates infoView
leads to a runtime error.
I am trying to have a text box appear next to each bubble in the bubble plot when the user touches that bubble. Similar to the dialog box in AreasExample.swift, I want the dialog box next to the bubble to display a string stored in a field of ChartPointBubble.
My understanding is that I need to pass a modification of circleViewGenerator
as the viewGenerator for chartPointsBubbleLayer. I am unsure of how to mesh AreasExample.swift and BubbleExample.swift to achieve this. BubbleExample.swift has a local version of BubbleView. BubbleExample.swift seems to not need a viewGenerator, which makes me all the more uncertain of how to insert it.
I have a situation in which I wish to graph data for which the typical case sees X-values increase before decreasing again, whilst the Y-values simply decrease - picture a capital D (without the vertical line and each data point is discrete and will vary with an inputted array).
An example of the arrays may be:
x = [0, 20, 30, 35, 25, 0]
y = [100, 80, 60, 40, 20, 0]
As such, most of the typical line graph libraries available won't work as they all work for linearly increasing X-values (will only allow one y-value for each x). One solution that I had considered is rotating the graph 90 degrees and reversing the x and y values such that there is only one discrete x-value for all y-values.
However I was also wondering if it was possible to draw lines between the data points on your scatter plot and how one might go about doing this?
I understand that there might be some difficulty with ordering of values and perhaps the library isn't built for scatter plots to include any line drawing capability.
Any help would be much appreciated!
It is great that the user can click on a point in the scatter plot and receive more information.
How would I enable the user to navigate to a detail page that contains further information about the point?
I envision a storyboard that begins with a tab control. One tab takes the user to the scatter plot. The other tab takes the user through a master-detail sequence. This way the user can access the further detail about the points by scrolling through a tabulation of the points or by clicking them on the screen.
I know that one would have to link DetailViewController with the viewGenerator for the scatter plot. I'm not sure where to put that linkage in the ViewController for the scatter plot.
Thanks
Very nice and useful tutorials, I'm trying to learn using your library with them.
However I cannot get how to use auto layout.
Is there a simple way to solve this not programmatically?
Thanks
I tried to run the code on both xcode 6.4 and 7 beta 4 gave compilation error. I tried to convert the code to the latest version of swift, and keeps giving error. I wonder if a specific configuration is required to run the code?
thanks
Using cubic lines and Data with a high slope after period of axial values causes a short decrease of the functions Graph. The following data example should not result in values below 0.0 :
data = [(name: "", quantity: 0.0), (name: "12:00", quantity: 0.0), (name: "", quantity: 0.0), (name: "", quantity: 60.0), (name: "", quantity: 57.0), (name: "", quantity: 50.0), (name: "", quantity: 150.0), (name: "18:00", quantity: 135.0), (name: "", quantity: 125.0), (name: "", quantity: 120.0), (name: "", quantity: 110.0), (name: "", quantity: 210.0), (name: "", quantity: 180.0), (name: "00:00", quantity: 165.0), (name: "", quantity: 142.0), (name: "", quantity: 120.0), (name: "", quantity: 100.0), (name: "", quantity: 80.0), (name: "", quantity: 75.0), (name: "06:00", quantity: 65.0), (name: "", quantity: 59.0), (name: "", quantity: 57.0), (name: "", quantity: 55.0), (name: "", quantity: 54.0)]
Hi, first of all thanks for this fine piece of Software.
Would it be easy to plot live data that changes something like 50 times a second and gives the data in an array of doubles?
We are looking for a performant solution to present data in a live situation.
Thanks and regards, Rainer from Germany :-)
Hello,
I can say....your collection is fantastic. A real tool for them they want a chart library!!!
Thanks a lot for your work.
I want to propose an enhancement for them they love objective c
Is it possible to have your tools in objective c also?
One more time thanks you very much.
George Gerardis
Hi,
When I use: stride(from: 0, through: x, by: 10) I get an error while compiling, how can I set the "through" to be a variable and not a static value?
like: stride(from: 0, through: x, by: 10) instead of stride(from: 0, through: 10, by: 10)
the compile error: cannot invoke map with an argument of type ((_) -> _)
Thanks in advance.
Delete it please.
Hi Ivan,
I'm trying to import the framework into a project (via pods) but am having a few issues I thought you might be able to shed some light on.
First of all, I'm getting 6 compiler errors from the pods and an additional error "No Such Module" when I attempt to import the framework (images attached).
The steps I've followed are merely setup and installed the podfile with the Swift 2.0 branch, opened the workspace in xCode 6.3.1, inputted the import statement and built the project.
Thanks for your help!
P.S. in reference to my previous question involving getting the touch point to move between two different points on the y-axis, I managed to develop a method, although I am sure it could be done more elegantly - happy to upload if you are interested.
when can you update a new version support swift2
This issue is more a problem of mine I think, but after many spent time i cannot still figure it out...
Why does this code (rougthly the same as the tracker example one) doesn't display anything else than the curve?
The datepicker bug is something else, sorry for it. but only the red plot appears. (i tryed on other circumstances before with full view on the curve)
It may be trivial but I can't find a logical explanation/solution...
Hi, I tried implementing new swift 2.0 version and I have entirely removed and rebuild the framework (cart file, cart update...), got the framework in the project folder, imported it to XCODE project in the the General part under Linked Framework and libraries, put the input file "$(SRCROOT)/Carthage/Build/iOS/SwiftCharts.framework" under run scripts.
After I build I always get the error:
dyld: Library not loaded: @rpath/libswiftSecurity.dylib
Referenced from: /Users/currentuser/Library/Developer/CoreSimulator/Devices/5D1EFC15-79C5-4A91-9C38-3DF1DD8D7B06/data/Containers/Bundle/Application/DAFD269F-0E16-44D4-A237-E6D30706924A/UBS Funds.app/Frameworks/SwiftCharts.framework/SwiftCharts
Reason: image not found
I tried the online solutions without success:
It worked in XCODE 6.4 with swift 1.2, do you have any ideas?
Thanks,
Pavle
Hi, in the Show touch coords (interactive) example, how can I make the circle highlighted (i.e. selected) when there is a selection? Right now it is showing the line and co-ord but I just want the circle highlighted instead (to keep it simple).
I noticed that in Areas,line,circles example, the circle is highlighted but I didn't want to have text inside.
So I am a little unsure what classes to use to accomplish the simple scenario. Thanks a lot for your help.
Hi,
i installed this framework but i get same 6 errors on different lines with ExamplesDefaults:
ex.: LineChart.swift:23:54: Use of unresolved identifier 'ExamplesDefaults'
Im using xCode 7 Beta 4
Where can be the problem?
Hi, newbie cocoapods help please.
I'm having trouble installing the pod.
I am getting the following error:
[!] Unable to satisfy the requirements Following:
SwiftCharts (from
https: // github.com / i-Schuetz / SwiftCharts.git, branch
swift2.0) required by
Podfile
I followed the following steps:
And I used the Podfile seguite:
use_frameworks!
pod 'SwiftCharts': git => 'https://github.com/i-schuetz/SwiftCharts.git': branch => 'swift2.0'
How I do I solve this problem?
Thanks,
Geraldo Roberson
Please change deployment target from 8.4 to lower (8.0). Downloaded using Carthage and when added to project and on import SwiftCharts, compiler gives an error:
module file's minimum deployment target is ios 8.4 v8.4
I worked around like this: changed it manually and carthage build and then droped the library
Thx in advance.
I was trying to define the xAxis and yAxis values using Double values.
I tried using ChartAxisValue but with no luck the numbers do not appear while the chart is presented.
Any idea how to define xValues without using .map, or giving a more detailed explanation?
I am looking to re-size a graph, in specific your scatter plot. What is the best way to do that? I would ideally like to have a scroll view in which the graph would occupy a portion of the screen while having a few things above/below it like buttons and text fields for inputs but would like to know how to resize the graph such that it won't occupy the entire view.
Thanks!
Hey,
first of all, thanks for the library!
I have a question on scrolling. In the examples scrolling is enabled through a UIScrollView which contains the hole chart-view. That way the y-axis isn't visible any more when the user scrolls.
Would it be possible to implement that the axis stay visible? Could you describe which steps would be required to take (high level), then I would try :)
Is there a way to create a LineChart that can be updated, say every 5 seconds, with a new datapoints, and will smoothly scroll to the left as the data is added?
I am trying to include SwiftCharts in a small graphing app targeted at iOS 8 or later.
Swift Chart is the only library beyond UIKit in my app. I am programming in Swift.
I installed CocoaPods, and linked to the SwiftCharts pod without trouble. The same issues arise on versions 0.1 and 0.2.
Hi, I am a swift newbie and I am confused by the pod file thing.
Here is what I did:
I've been working on doing this myself, but I've come to a point where I think it would be helpful for you to provide some input as to where this should go.
An example of what I mean: There is a ChartLayer protocol for conforming types to be able to draw in a chart's context. There is then a single ChartLayerBase base class that implements this protocol with empty methods for subclasses to override if necessary. This seems like a mixture of two different concepts that ends up negating any potential benefits of either. I.e. Anything that would implement the protocol probably will end up just subclassing the base class, and any of the benefits of using protocols instead of inheritance is lost. The situation with ChartAxisLayer is similar.
In investigating alternatives, I found that when mixing protocols with default implementations and class inheritance, the rulers for which method implementation gets called is a little different than what one might think, and so a simple change ends up not working.
Instead I'd propose using protocols strictly for describing a defined set of behaviour of a type instead of a particular component of a chart. For example: the ChartLayer protocol could be renamed to DrawableLayer, have empty default implementations of its methods, and the different kinds of components of a chart (ChartAxisLayer
, ChartCoordsSpaceLayer
, etc. and their subclasses) would each implement this protocol. This would also involve removing the ChartAxisLayer
protocol in favour of the existing ChartAxisLayerDefault
base class.
I've gotten this far on a branch of SwiftCharts, and then I noticed that there is also a ChartContextDrawer
base class that looks a lot like my new DrawableLayer
protocol. So I think this is where I need input from you! Although there might be a difference between the kinds of chart components that conform to/subclass ChartLayer
and ChartContextDrawer
, the two interfaces are almost exactly the same and I think they should be one and the same or at least more closely related. Is there a reason that these were separate before?
Example, where these could also be a single protocol:
protocol Drawable {
func initialize(chart: Chart)
func draw(context: CGContextRef, chart: Chart)
}
protocol Hideable: Drawable {
var hidden: Bool { get, set }
}
extension Hideable {
func drawIfVisible(context: CGContextRef, chart: Chart) {
if !hidden {
draw(context: context, chart: chart)
}
}
}
Hi,
I am using the simple code as you provided to generate the chart. But the chart seems be cut by the edge of the frame. (I can not see the top half of 200 and right half of 100). Could you help to figure out the problem? thanks
import UIKit
import SwiftCharts
class ChartViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//new code
self.view.addSubview(chart.view)
}
let chartConfig : ChartConfigXY!
let chart : LineChart!
required init(coder aDecoder: NSCoder) {
self.chartConfig = ChartConfigXY(
xAxisConfig: ChartAxisConfig(from: 0, to: 100, by: 20),
yAxisConfig: ChartAxisConfig(from: 0, to: 200, by: 40)
)
self.chart = LineChart(
frame: CGRectMake(10, 80, 300, 200),
chartConfig: chartConfig,
xTitle: "Time (s)",
yTitle: "Pressures (cm H2O)",
lines: [
(chartPoints: [(12.0, 50.6), (14.2, 85.1), (17.3, 123.0), (18.1, 135.5), (94.0, 148.0)], color: UIColor.redColor()),
(chartPoints: [(12.0, 52.6), (14.2, 59.1), (17.3, 61.0), (18.1, 90.5), (94.0, 113.0)], color: UIColor.blueColor())
]
)
super.init(coder: aDecoder)
}
}
Just delete a question mark behind init.
Hey,
what is the recommended way to update an existing chart (delete, update or insert values)? Is there anything better than recreate the hole chart?
Many thanks!
I would be interested by the automatic addition of trendlines to line charts.
Simple linear trendlines are sufficient for my intended use, however I suppose higher order trendlines are of general interest too.
New to iOS dev and really like what you've done here. Just wondering - what is the best way to deal with a screen rotation and redrawing a chart with different bounds. Thanks!
Hello
I'm trying out your library for the first time and noticing that none of your example works with it's current build. Would be nice to have this updated so that I can understand what things do instead of trying to debug it.
Great Library! The examples look great. When I rotate, the landscape doesn't fill the frame. When I rotate back to prostrate, part of the graph is cut off. This happens with and without using auto layout.
Here's the ViewController I'm using:
// Copyright © 2015 us.rickstreet. All rights reserved.
//
import UIKit
import SwiftCharts
class ViewController: UIViewController {
private var chart: Chart? // arc
@IBOutlet weak var chartView: ChartBaseView!
private var didLayout: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if !self.didLayout {
self.didLayout = true
self.initChart()
}
}
private func initChart() {
for index in 5.stride(through: 1, by: -1) {
print(index)
}
// map model data to chart points
let chartPoints: [ChartPoint] = [(2, 2), (4, 4), (6, 6), (8, 10), (12, 14)].map{ChartPoint(x: ChartAxisValueInt($0.0), y: ChartAxisValueInt($0.1))}
let labelSettings = ChartLabelSettings(font: ExamplesDefaults.labelFont)
// define x and y axis values (quick-demo way, see other examples for generation based on chartpoints)
let xValues = 0.stride(through: 16, by: 2).map {ChartAxisValueInt($0, labelSettings: labelSettings)}
let yValues = 0.stride(through: 16, by: 2).map {ChartAxisValueInt($0, labelSettings: labelSettings)}
// create axis models with axis values and axis title
let xModel = ChartAxisModel(axisValues: xValues, axisTitleLabel: ChartAxisLabel(text: "Axis title", settings: labelSettings))
let yModel = ChartAxisModel(axisValues: yValues, axisTitleLabel: ChartAxisLabel(text: "Axis title", settings: labelSettings.defaultVertical()))
let chartFrame = self.chartView.frame
// generate axes layers and calculate chart inner frame, based on the axis models
let coordsSpace = ChartCoordsSpaceLeftBottomSingleAxis(chartSettings: ExamplesDefaults.chartSettings, chartFrame: chartFrame, xModel: xModel, yModel: yModel)
let (xAxis, yAxis, innerFrame) = (coordsSpace.xAxis, coordsSpace.yAxis, coordsSpace.chartInnerFrame)
// create layer with guidelines
let guidelinesLayerSettings = ChartGuideLinesDottedLayerSettings(linesColor: UIColor.blackColor(), linesWidth: ExamplesDefaults.guidelinesWidth)
let guidelinesLayer = ChartGuideLinesDottedLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, settings: guidelinesLayerSettings)
// view generator - this is a function that creates a view for each chartpoint
let viewGenerator = {(chartPointModel: ChartPointLayerModel, layer: ChartPointsViewsLayer, chart: Chart) -> UIView? in
let viewSize: CGFloat = Env.iPad ? 30 : 20
let center = chartPointModel.screenLoc
let label = UILabel(frame: CGRectMake(center.x - viewSize / 2, center.y - viewSize / 2, viewSize, viewSize))
label.backgroundColor = UIColor.greenColor()
label.textAlignment = NSTextAlignment.Center
label.text = "\(chartPointModel.chartPoint.y.text)"
label.font = ExamplesDefaults.labelFont
return label
}
// create layer that uses viewGenerator to display chartpoints
let chartPointsLayer = ChartPointsViewsLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: chartPoints, viewGenerator: viewGenerator)
// create chart instance with frame and layers
let chart = Chart(
view: self.chartView!,
layers: [
coordsSpace.xAxis,
coordsSpace.yAxis,
guidelinesLayer,
chartPointsLayer
]
)
self.chart = chart
}
func rotated() {
for view in self.chartView.subviews {
view.removeFromSuperview()
}
self.initChart()
}
}
Thanks,
Rick
Thanks! (I'm newbie)
In the Areas line, circles (interactive) example, the popup is shown and previous popup is clear whenever I clicked on a circle. How can I clear the popup if I click on any place on the graph that is not the circle (e.g. the white space). Thanks...
Zooming the scatter plot is available ???
Hi
I have been unsuccessful in implementing a tracker layer using my own ChartAxisValue, it does not seem to be calling my override var text: String
. Here is code replicating the issue:
//
// MultipleAxesInteractiveExample.swift
// SwiftCharts
//
// Created by ischuetz on 04/05/15.
// Copyright (c) 2015 ivanschuetz. All rights reserved.
//
import UIKit
import SwiftCharts
class MyAxisValue: ChartAxisValue {
let myVal: Int
let date: String
let chartLabelSettings: ChartLabelSettings
var labelIndexToDisplay = [0,1,2,3,4,5] // An array of valid indexes to show labels
init(myVal: Int, date: String, chartLabelSettings: ChartLabelSettings) {
self.myVal = myVal
self.date = date
self.chartLabelSettings = chartLabelSettings
super.init(scalar: Double(myVal))
}
// This override doesnt get called?
override var text: String {
return self.date
}
override var labels:[ChartAxisLabel] {
for var i = 0; i < labelIndexToDisplay.count; ++i {
if myVal == labelIndexToDisplay[i] {
return [ChartAxisLabel(text: date, settings: chartLabelSettings)]
}
}
return []
}
}
class MultipleAxesInteractiveExample: UIViewController {
private var chart: Chart?
let bgColors = [UIColor.redColor()]
private var showGuides: Bool = false
private var selectedLayersFlags = [true]
private var chartPoints0: [ChartPoint] = [ChartPoint]()
private var viewFrame: CGRect!
private var chartInnerFrame: CGRect!
private var yLowAxes: [ChartAxisLayer]!
private var xLowAxes: [ChartAxisLayer]!
private var guideLinesLayer0: ChartLayer!
var readFormatter = NSDateFormatter()
var displayFormatter = NSDateFormatter()
init() {
let labelSettings = ChartLabelSettings(font: ExamplesDefaults.labelFontSmall)
readFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
displayFormatter.dateFormat = "dd-MM-yy\nHH:mm:ss"
super.init(nibName: nil, bundle: nil)
func createChartPointWithDate(x x: Int, date: NSDate, y: Double, labelColor: UIColor) -> ChartPoint {
let yLabelSettings = ChartLabelSettings(font: ExamplesDefaults.labelFontSmall, fontColor: labelColor)
let xLabelSettings = ChartLabelSettings(font: ExamplesDefaults.labelFontSmall, rotation: 90, rotationKeep: .Bottom, fontColor: labelColor)
// Calling my own axis value won't work, it does not call my text override computed variable
return ChartPoint(x: ChartAxisValueDate(date: date, formatter: readFormatter, labelSettings: xLabelSettings), y: ChartAxisValueDouble(y, labelSettings: yLabelSettings))
// Calling existing ChartAxisValues##### work. They call the text overrides correctly
//return ChartPoint(x: ChartAxisValueDouble(x, labelSettings: xLabelSettings), y: ChartAxisValueDouble(y, labelSettings: yLabelSettings))
}
self.chartPoints0.append(createChartPointWithDate(x: 0, date: readFormatter.dateFromString("2015-10-28 22:30:17")!, y: 115.15, labelColor: bgColors[0]))
self.chartPoints0.append(createChartPointWithDate(x: 1, date: readFormatter.dateFromString("2015-10-28 22:32:17")!, y: 115.15, labelColor: bgColors[0]))
self.chartPoints0.append(createChartPointWithDate(x: 2, date: readFormatter.dateFromString("2015-10-28 22:34:17")!, y: 115.15, labelColor: bgColors[0]))
self.chartPoints0.append(createChartPointWithDate(x: 3, date: readFormatter.dateFromString("2015-10-28 22:36:17")!, y: 115.15, labelColor: bgColors[0]))
self.chartPoints0.append(createChartPointWithDate(x: 4, date: readFormatter.dateFromString("2015-10-28 22:38:17")!, y: 115.15, labelColor: bgColors[0]))
self.chartPoints0.append(createChartPointWithDate(x: 5, date: readFormatter.dateFromString("2015-10-28 22:40:17")!, y: 115.15, labelColor: bgColors[0]))
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
let xValues0 = self.chartPoints0.map{$0.x}
let chartSettings = ExamplesDefaults.chartSettings
let top: CGFloat = 80
self.viewFrame = CGRectMake(0, top, 375, 550)
var yValues0 = [ChartAxisValue]()
yValues0.append(ChartAxisValueString("normal", order: 115, labelSettings: ChartLabelSettings(font: ExamplesDefaults.labelFontSmall, fontColor: self.bgColors[0])))
yValues0.append(ChartAxisValueString("", order: 114, labelSettings: ChartLabelSettings(font: ExamplesDefaults.labelFontSmall, fontColor: self.bgColors[0])))
yValues0.append(ChartAxisValueString("", order: 116, labelSettings: ChartLabelSettings(font: ExamplesDefaults.labelFontSmall, fontColor: self.bgColors[0])))
let axisTitleFont = ExamplesDefaults.labelFontSmall
let yLowModels: [ChartAxisModel] = [
ChartAxisModel(axisValues: yValues0, lineColor: self.bgColors[0], axisTitleLabels: [ChartAxisLabel(text: "", settings: ChartLabelSettings(fontColor: self.bgColors[0], font: axisTitleFont).defaultVertical())])
]
let xLowModels: [ChartAxisModel] = [
ChartAxisModel(axisValues: xValues0, lineColor: self.bgColors[0], axisTitleLabels: [ChartAxisLabel(text: "", settings: ChartLabelSettings(fontColor: self.bgColors[0], font: axisTitleFont))])
]
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
let coordsSpace = ChartCoordsSpace(chartSettings: chartSettings, chartSize: self.viewFrame.size, yLowModels: yLowModels, xLowModels: xLowModels)
dispatch_async(dispatch_get_main_queue()) {
self.chartInnerFrame = coordsSpace.chartInnerFrame
self.yLowAxes = coordsSpace.yLowAxes
self.xLowAxes = coordsSpace.xLowAxes
let guideLinesLayer0Settings = ChartGuideLinesDottedLayerSettings(linesColor: self.bgColors[0], linesWidth: ExamplesDefaults.guidelinesWidth)
self.guideLinesLayer0 = ChartGuideLinesDottedLayer(xAxis: self.xLowAxes[0], yAxis: self.yLowAxes[0], innerFrame: self.chartInnerFrame, settings: guideLinesLayer0Settings)
self.showChart(lineAnimDuration: 1)
}
}
}
private func createLineLayers(animDuration animDuration: Float) -> [ChartPointsLineLayer<ChartPoint>] {
let lineModel0 = ChartLineModel(chartPoints: chartPoints0, lineColor: bgColors[0], animDuration: animDuration, animDelay: 0)
// Controls which axis the line will use to draw the graph
let chartPointsLineLayer0 = ChartPointsLineLayer<ChartPoint>(xAxis: xLowAxes[0], yAxis: yLowAxes[0], innerFrame: chartInnerFrame, lineModels: [lineModel0])
return [chartPointsLineLayer0]
}
private func createLayers(selectedLayersFlags selectedLayersFlags: [Bool], showGuides: Bool, lineAnimDuration: Float) -> ([ChartLayer]) {
var axisLayers: [ChartLayer] = []
var itemsLayers: [ChartLayer] = []
let lineLayers = self.createLineLayers(animDuration: lineAnimDuration)
func maybeGuides(guideLayer: ChartLayer) -> [ChartLayer] {
return (showGuides ? [guideLayer] : [])
}
//*************
// Tracker
let trackerLayerSettings = ChartPointsLineTrackerLayerSettings(thumbSize: Env.iPad ? 30 : 20, thumbCornerRadius: Env.iPad ? 16 : 10, thumbBorderWidth: Env.iPad ? 4 : 2, infoViewFont: ExamplesDefaults.fontWithSize(Env.iPad ? 26 : 16), infoViewSize: CGSizeMake(Env.iPad ? 400 : 160, Env.iPad ? 70 : 40), infoViewCornerRadius: Env.iPad ? 30 : 15)
let chartPointsTrackerLayer = ChartPointsLineTrackerLayer(xAxis: xLowAxes[0], yAxis: yLowAxes[0], innerFrame: chartInnerFrame, chartPoints: chartPoints0, lineColor: UIColor.blackColor(), animDuration: 1, animDelay: 2, settings: trackerLayerSettings)
//*************
let layers: [[ChartLayer]] = [
[yLowAxes[0], xLowAxes[0], lineLayers[0], chartPointsTrackerLayer] + maybeGuides(guideLinesLayer0)
]
return selectedLayersFlags.enumerate().reduce(Array<ChartLayer>()) {selectedLayers, inTuple in
let index = inTuple.0
let selected = inTuple.1
if selected {
return selectedLayers + layers[index]
}
return selectedLayers
}
}
private func showChart(lineAnimDuration lineAnimDuration: Float) -> () {
self.chart?.clearView()
let layers = self.createLayers(selectedLayersFlags: self.selectedLayersFlags, showGuides: self.showGuides, lineAnimDuration: lineAnimDuration)
let view = ChartBaseView(frame: viewFrame)
let chart = Chart(
view: view,
layers: layers
)
self.view.addSubview(chart.view)
self.chart = chart
}
}
Calling:
return ChartPoint(x: ChartAxisValueDouble(x, labelSettings: xLabelSettings), y: ChartAxisValueDouble(y, labelSettings: yLabelSettings))
works.
Calling return ChartPoint(x: ChartAxisValueDate(date: date, formatter: readFormatter, labelSettings: xLabelSettings), y: ChartAxisValueDouble(y, labelSettings: yLabelSettings))
causes an app crash because it does not call my text override.
Are you able to shed any light on this issue?
Thanks
I'm using SwiftCharts with AutoLayouts where I want the chart to the same width as the container UIView. I'm having problems where the chart is being clipped off the bounds.
I set the bounds to the same as the UIView which adds the chart. Any ideas?
func calcChartFrame(containerBounds: CGRect) -> CGRect {
return CGRectMake(0, 70, containerBounds.size.width, containerBounds.size.height - 70)
}
let chartFrame = calcChartFrame(self.chartView.bounds)
Here's a more full snippet:
@IBOutlet weak var chartView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
self.addChart()
}
func addChart() {
self.chartView.backgroundColor = UIColor.whiteColor()
let labelFont = UIFont.systemFontOfSize(14)
let labelSettings = ChartLabelSettings(font: labelFont)
let chartSettings: ChartSettings = {
let chartSettings = ChartSettings()
chartSettings.leading = 10
chartSettings.top = 10
chartSettings.trailing = 10
chartSettings.bottom = 10
chartSettings.labelsToAxisSpacingX = 5
chartSettings.labelsToAxisSpacingY = 5
chartSettings.axisTitleLabelsToLabelsSpacing = 4
chartSettings.axisStrokeWidth = 0.2
chartSettings.spacingBetweenAxesX = 8
chartSettings.spacingBetweenAxesY = 8
return chartSettings
}()
let guidelinesWidth = CGFloat(0.1)
func calcChartFrame(containerBounds: CGRect) -> CGRect {
return CGRectMake(0, 70, containerBounds.size.width, containerBounds.size.height - 70)
}
let chartPoints = [(1, 10), (3, 20), (4, 5), (5, 25), (8, 10)].map{ChartPoint(x: ChartAxisValueInt($0.0), y: ChartAxisValueInt($0.1))}
let xValues = ChartAxisValuesGenerator.generateXAxisValuesWithChartPoints(chartPoints, minSegmentCount: 7, maxSegmentCount: 7, multiple: 2, axisValueGenerator: {ChartAxisValueFloat($0, labelSettings: labelSettings)}, addPaddingSegmentIfEdge: false)
let yValues = ChartAxisValuesGenerator.generateYAxisValuesWithChartPoints(chartPoints, minSegmentCount: 2, maxSegmentCount: 5, multiple: 2, axisValueGenerator: {ChartAxisValueFloat($0, labelSettings: labelSettings)}, addPaddingSegmentIfEdge: true)
let xModel = ChartAxisModel(axisValues: xValues, axisTitleLabel: ChartAxisLabel(text: "Days", settings: labelSettings))
let yModel = ChartAxisModel(axisValues: yValues, axisTitleLabel: ChartAxisLabel(text: "Duration", settings: labelSettings.defaultVertical()))
let chartFrame = calcChartFrame(self.chartView.bounds)
let coordsSpace = ChartCoordsSpaceLeftBottomSingleAxis(chartSettings: chartSettings, chartFrame: chartFrame, xModel: xModel, yModel: yModel)
let (xAxis, yAxis, innerFrame) = (coordsSpace.xAxis, coordsSpace.yAxis, coordsSpace.chartInnerFrame)
let showCoordsTextViewsGenerator = {(chartPointModel: ChartPointLayerModel, layer: ChartPointsLayer, chart: Chart) -> UIView? in
let (chartPoint, screenLoc) = (chartPointModel.chartPoint, chartPointModel.screenLoc)
let w: CGFloat = 70
let h: CGFloat = 30
let text = "(\(chartPoint.x.text), \(chartPoint.y.text))"
let font = labelFont
let textSize = ChartUtils.textSize(text, font: font)
let x = min(screenLoc.x + 5, chart.bounds.width - textSize.width - 5)
let view = UIView(frame: CGRectMake(x, screenLoc.y - h, w, h))
let label = UILabel(frame: view.bounds)
label.text = "\(chartPoint.y.text) mins"
label.font = labelFont
view.addSubview(label)
view.alpha = 0
UIView.animateWithDuration(0.2, delay: 0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in
view.alpha = 1
}, completion: nil)
return view
}
let showCoordsLinesLayer = ChartShowCoordsLinesLayer<ChartPoint>(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: chartPoints)
let showCoordsTextLayer = ChartPointsSingleViewLayer<ChartPoint, UIView>(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: chartPoints, viewGenerator: showCoordsTextViewsGenerator)
let touchViewsGenerator = {(chartPointModel: ChartPointLayerModel, layer: ChartPointsLayer, chart: Chart) -> UIView? in
let (chartPoint, screenLoc) = (chartPointModel.chartPoint, chartPointModel.screenLoc)
let s: CGFloat = 30
let view = HandlingView(frame: CGRectMake(screenLoc.x - s/2, screenLoc.y - s/2, s, s))
view.touchHandler = {
showCoordsLinesLayer.showChartPointLines(chartPoint, chart: chart)
showCoordsTextLayer.showView(chartPoint: chartPoint, chart: chart)
}
return view
}
let touchLayer = ChartPointsViewsLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: chartPoints, viewGenerator: touchViewsGenerator)
let lineModel = ChartLineModel(chartPoints: chartPoints, lineColor: UIColor(red: 0.4, green: 0.4, blue: 1, alpha: 0.2), lineWidth: 3, animDuration: 0.7, animDelay: 0)
let chartPointsLineLayer = ChartPointsLineLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, lineModels: [lineModel])
let circleViewGenerator = {(chartPointModel: ChartPointLayerModel, layer: ChartPointsLayer, chart: Chart) -> UIView? in
let circleView = ChartPointEllipseView(center: chartPointModel.screenLoc, diameter: 18)
circleView.animDuration = 1.5
circleView.fillColor = UIColor.whiteColor()
circleView.borderWidth = 5
circleView.borderColor = UIColor.blueColor()
return circleView
}
let chartPointsCircleLayer = ChartPointsViewsLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, chartPoints: chartPoints, viewGenerator: circleViewGenerator, displayDelay: 0, delayBetweenItems: 0.05)
var settings = ChartGuideLinesDottedLayerSettings(linesColor: UIColor.blackColor(), linesWidth: guidelinesWidth)
let guidelinesLayer = ChartGuideLinesDottedLayer(xAxis: xAxis, yAxis: yAxis, innerFrame: innerFrame, settings: settings)
let chart = Chart(
frame: chartFrame,
layers: [
xAxis,
yAxis,
guidelinesLayer,
showCoordsLinesLayer,
chartPointsLineLayer,
chartPointsCircleLayer,
showCoordsTextLayer,
touchLayer,
]
)
self.chartView.addSubview(chart.view)
}
Hello,
im using Xcode 7 Beta 6, now i get the error:
"..../SwiftCharts/Convenience/BarsChart.swift:34:29: 'stride(from:through:by:)' is unavailable: call the 'stride(through:by:)' method instead"
is there a fix in the next time?
thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.