Add annotation programmatically to core plot scatter plot give the X (date value) and Y - ios

I am drawing a stock price chart using Core Plot objective-c library.
I need to add annotations to the graph (preferably custom view), programmatically, not on graph touch action. I have a list of x&y (x is a date and y is the price).
Is there an easy way to do this? and how?
Thank you.

Use this code block:
self.priceAnnotation.anchorPlotPoint = [NSArray arrayWithObjects:anchorX, anchorY, nil];
// 8 - Add the annotation
[plot.graph.plotAreaFrame.plotArea addAnnotation:self.priceAnnotation]; // change variable names accordingly
For more details, refer this one, answer for your question is already available here;
http://www.raywenderlich.com/13271/how-to-draw-graphs-with-core-plot-part-2
This tutorial is really helpful. Part-1 and Part-2 both.

Related

How to shift data on xAxis to right on Daniel Gindi charts?

I have a data chart DataChart would like to shift data of xAxis along with data lines to right by certain value.
DataChart Screen Shot
Please help me out which property to use from the library that would be able to solve this purpose.
I am using Daniel Gindi line charts for this purpose.
I use this to create an offset to the left of my chart
myChart.xAxis.spaceMin = 10
maybe it'll do for you
And to align the yAxis lines in front of the labels, i think you could remove the background grid and create your own limit lines if you don't find any other way around
is it viable to subtract the distance d from the x values? that would shift it rightward.
d = 7.0
rightShifted = newGraphData.values.map{ChartDataEntry(x:$0.x-d, y:$0.y)}

shinobi chart gridline end in data point instead of going all the way to the top of chart

I'm drawing a chart in an iOS app and I want the gridlines to start in the x axis but end in the data point instead of extending all the way up to the top.
Is this possible?
Thanks in advance.
NC
Disclaimer: I work for ShinobiControls
The shinobicharts framework doesn't currently support this as an out-of-the-box feature.
A workaround may exist though. You may be able to add your own gridline subviews by using the SChartAxis method pixelValueForDataValue: to work out where in the plot area coordinate space you should draw your vertical line up to for a given data point.
Once you have your coordinates there are various ways you could draw your gridlines:
Add a canvas view behind or in front of the chart (depending on what effect you want). Then use your coordinates to draw your gridlines using CoreGraphics or some other drawing technique.
Create individual UIViews that each represent a gridline using your coordinates and add these behind or in front of the chart.
One thing to be aware of with this technique is that the gridlines will not automatically update when you pan and zoom. In order to do this you will need to override one of the chart's delegate methods that notify you of range changes and update your drawn gridlines to match the new data point positions.
Another potential workaround could be to use a column series to mimic gridlines. If you create a column series and feed it the same data points as your original series this will result in columns that go up to the y-value of each data point. You could then use the property interSeriesSetPadding on SChartAxisStyle to cause the columns to appear very thin.
I hope that information is useful!

Coreplot Graph Scaling Issue

I have two graphs which have variable range of X and Y values.
The following graph-scaling was attained of using the scaleToFitPlots:(NSArray *)plots method.
But my intention is to get the scaling look like following and I can't find any suitable method in CorePlot framework to accomplish it. Some pointers on it would be very appreciated.
If you already know the ranges you want displayed, skip calling -scaleToFitPlots: and set the xRange and yRange directly.

Core Plot - How to display axis labels under plot?

I'm working with a CorePlot scatter plot, and I'm having trouble putting the finishing touches on the axis label styling. I'd like for the plot to overlap above the Y-axis labels, but the opposite is happening. I've scoured the documentation, but can't find any options to do this.
Here's the output:
I've tried manipulating the ZPosition of both the plot & axis labels, but that doesn't seem to be working:
[plot setZPosition:99];
[axisSet.yAxis.axisLabels each:^(CPTAxisLabel *label) {
[label.contentLayer setZPosition:-1];
}];
Note - Objective Sugar used for loop comprehension
Any ideas as to how to accomplish this?
The plot area has a property called topDownLayerOrder that allows you to rearrange the different graph elements in exactly this way.

How to display live core plot graph in iPad? [duplicate]

I want to use core-plot for drawing line graph dynamically. data won't come at a time, we will be receiving point by point dynamically.
Is it possible to draw the chart dynamically using core-plot i.e drawing point by point as on when we receive the (x,y) point?
Please help me, Thanks.
Yes, you can do this reasonably easily. For each received data point, append it to an array of values to display. As these data points come in, call -reloadData on the Core Plot graph (or just the particular plot) to redraw the graph, passing in the array you just added a value to in response to the -numbersForPlot:field:recordIndexRange: delegate method.
If you need to adjust the plot range to track your data points (for a moving ticker), recalculate the new CPPlotRange for the X axis and set the plot space's xRange property to that.
Use the CPTestApp-iPhone, AAPLot, or StockPlot examples as templates for how to set up the line chart overall, and modify from that starting point.
I do something similar to this on the Mac in a scientific application:
(source: sunsetlakesoftware.com)
Sounds like you could make use of a demo project I put together and wrote about here (not core plot related though).
It draws a EKG graph but should easily be modified to use another input than the repeated "heart beat"...See line 320 in EAGLView.m where the indata is entered into the array.

Resources