I am trying to add the CPTLegend in uiview how can i add.Basically many people adding in Graph hosting view. Any idea?
All visible parts of a Core Plot graph, including the legend (drawn by CPTLegend), are Core Animation layers that are derived from a common superclass, CPTLayer. These layers rely on the hosting view to set up the coordinate transform and event handling and to handle layout changes.
Why do you need to have a legend that is not attached to a graph? CPTLegend depends on plots both to determine the contents of the legend and to actually draw it. These plots are normally part of a graph, so you should have one available to use as a host for the legend.
Enlarge the hosting view to cover the whole area where the pie chart and legend should appear. Change the centerAnchor of the pie chart to move it away from the center of the hosting view and position the legend on the other side of the graph. The separator view can be placed on top of the hosting view to separate the plot from the legend. Note that Core Animation hosting views don't allow subviews, so it needs to be a sibling (i.e., have the same superview) of the hosting view, not a subview.
Related
I am using Highcarts with React to create a dynamic line graph. On the graph there is a series for a vertical line which can be moved around the graph in response to some user inputs elsewhere on the page.
The problem I am having is that when the vertical line is dragged to either end of the graph, Highcharts automatically adjusts the plotting area to make space for it, resulting in the graph shifting to the left or right.
I would like to turn this off and allow enough space on either side of the graph so that no automatic adjustment of the graph is performed. I have tried setting margin and spacing parameters of the chart but they do not extend the plot area in the way I need.
Thanks
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!
I am working on core Plot library in ios.I was able to add mutliple scatter plots to graph.I am not able to achieve following customizations(Pls refer attached image):
Need to connect multiple Y-axis points and draw a vertical line.
On X-axis,need to add number of tasks(Custom UI views) for every month.
Thanks for any help you can give.
Use a third scatter plot to draw the vertical lines.
Don't add subviews to the Core Plot hosting view. Add them to the hosting view's superview. You can use the plot space to find the coordinates along the x-axis to anchor your custom views.
I achieved to plot my 5 lines, but wherever I place the legend, it doesn't allow me to see clearly the interception of some lines.
There is a way to allow the user to move/drag the legend along the plotting area?
No. You could position the legend outside the plot area so it doesn't overlap the plot or subclass CPTLegend and override the user interaction methods (-pointingDeviceDownEvent:atPoint:, etc.) to implement the dragging behavior.
I want to have 2 columns legend under the diagram, and I would like that they are on the sides of the screen, not on the left.
This how it's look like now:
How can I do it?
Core Plot legends have many options to customize the layout, including the size of the color swatch, the spacing between rows and columns, and the number of rows and/or columns in the grid. See the CPTLegend docs for the details.
The legend itself is just a CPTLayer (Core Animation CALayer subclass). The Core Plot graph provides convenience properties for positioning the legend (legendAnchor and legendDisplacement). If these don't provide enough control, you can position the legend layer anywhere you want using annotations. Use a layer annotation to tie the location to a specific graph layer (fixed screen position) or a plot space annotation so it moves with the plot data.
It's done only just by one line of code: theLegend.columnMargin = 90.0;
Or theLegend.columnWidths = arrOfWidths;