Search code examples
ioschartsshinobi

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


Solution

  • 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!