-
Notifications
You must be signed in to change notification settings - Fork 420
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
need Swift implementation details and example #80
Comments
I do agree. |
The easiest way to use this lib with Swift is to add it via Cocoapods to your project. #import "JBChartView/JBChartView.h"
#import "JBChartView/JBBarChartView.h"
#import "JBChartView/JBLineChartView.h" Then you need to specify the bridging header path in your target configuration. It's under the Build Settings tab, section "Swift Compiler - Code Generation" Hope it helps |
Since most of the delegate functions return UInt you'll need to explicitly covert values in Swift. For instance, setting up the basic functions for a line chart might look like this: func numberOfLinesInLineChartView(lineChartView: JBLineChartView!) -> UInt {
return 1 //number of lines in chart
}
func lineChartView(lineChartView: JBLineChartView!, numberOfVerticalValuesAtLineIndex lineIndex: UInt) -> UInt {
return UInt(chartData.count) //number of values for a line
}
func lineChartView(lineChartView: JBLineChartView!, verticalValueForHorizontalIndex horizontalIndex: UInt, atLineIndex lineIndex: UInt) -> CGFloat {
return CGFloat(chartData[Int(horizontalIndex)]) //y-position (y-axis) of point at horizontalIndex (x-axis)
} |
@DirkLXX @mbanasiewicz @nsimonson - could you share a complete sample code? I tried a simple barchart in swift and I see the area's background, but no bars:
I used println to make sure the methods were called; I get the following results:
I set the frame and called the reloadData after setting up the frame; any ideas why I do not see any bars? Thanks, |
@gregorifaroux You have it set up correctly. The minimum and maximum values of the chart are equal to the min and max values of the data source. In your case the min and max are both being set to 100. You can override the minimum and maximum values of the chart view by setting them on your barChartView before you call reloadData(). Or add some other values for the data source. |
@nsimonson Thank you! I replaced my fixed value with random numbers and it is working:
Here is the complete code if someone is looking for a Swift example:
|
Here is a full example using swift and a JSON REST Web Service to populate the data: https://github.com/gregorifaroux/swift-JBBarChartView-RESTAPI-JSON |
@gregorifaroux Hi , I tried your code but still i have no bar chart, Can you help me ? |
@shameer49 Hi, Sorry about this. Did you try the github link posted? Another trick is to set minimumValue and maximumValue.... For instance to 0 and 100 if your values are between 0 and 100. If you could post your code, I can have a look. Or if you create a git repository so I can look at the full code. Take care, Sent from my iPhone
|
Closing this. Please re-open if you are still having issues. |
Hi, I am trying to use it in a swift project.
however I am having a hard time getting it to work.
will it be possible to show an example
or
list step by step documentation instructions to make it work on a swift project
The text was updated successfully, but these errors were encountered: