Where can I read the CorePlot tutorial for Swift beginners?

104 views
Skip to first unread message

mymy...@gmail.com

unread,
Jul 3, 2017, 7:35:51 AM7/3/17
to coreplot-discuss
Hi, I'm a very beginner of not only Swift but also programming. My app needs a line chart like forex tick charts, whose data from iPhone sensor. I already tried using other libraries such as ios-Charts, Scrollable-Graph View, but they don't have all functions which I need. Therefore, I'd like to use CorePlot definitely, and I need some tutorials for Swift beginners, yet I couldn't find it. I used cocoapods to install CorePlot 2.2, and "import CorePlot" was successful. My ViewController has "@IBOutlet var lineChartView: CPTGraphHostingView!"(I removed "weak" already). I couldn't find the information that which "delegate" or "datasource" I should write in the "class ViewController" for a line chart. Any advice would be greatly appreciated. Many thanks!

Eric

unread,
Jul 3, 2017, 8:09:00 AM7/3/17
to coreplot-discuss
There are a few blog posts that discuss the basics, but I haven't had time to write up any "official" tutorials. The best way to start is to look through the provided example apps to find something similar to what you're trying to do and modify the code from there. The Plot Gallery app has the widest variety of plots. A couple of the examples are written in Swift (one each for Mac and iOS) so you have that as a reference to how the code changes from Objective-C. If you have specific questions after looking at the examples, ask them on this board or on StackOverflow using the core-plot tag.

In general, delegates are used to handle user interaction and custom drawing and the datasource provides plot data and data unique to each data point. The <CPTPlotDataSource> protocol provides the datasource methods shared by all plot types. Most plot types also have a datasource protocol that inherits from <CPTPlotDataSource> that provides additional information specific to that plot type. For example, the scatter plot datasource can also provide unique plot symbols for each data point.

Eric

Mayumi

unread,
Jul 3, 2017, 8:54:00 PM7/3/17
to coreplot-discuss
Hi, Eric, Thank you for your quick reply, and I could find the topic "Core Plot in Swift for Beginner" on StackOverflow, then it works. Unfortunately, I couldn't manage the <CPTPlotDataSource> in my class ("Type 'ViewController' does not conform to protocol 'CPTPlotDataSource'"), but could the < CPTPlotDelegate>. I'll try to write tutorial if I can. Thank you again for creating and maintaining great library.
Mayumi

Eric

unread,
Jul 4, 2017, 7:30:42 AM7/4/17
to coreplot-discuss
In Swift 3,

-(NSUInteger)numberOfRecordsForPlot:(nonnull CPTPlot *)plot


becomes

func numberOfRecords(for plot: CPTPlot) -> UInt


and


-(nullable id)numberForPlot:(nonnull CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index


becomes


func number(for plot: CPTPlot, field: UInt, record: UInt) -> Any?


Eric
Reply all
Reply to author
Forward
0 new messages