Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
40
Prevent column to touch top of graph
posted

See this image:

I'm using the delegate's [viewForMarkerInSeries...] to show the number above the columns. With an options.offsetY to show them above right above the columns.

However, for a bar that is exactly the value of the maximum round y-value this doesn't work (see red circle).

I would either like to have the y-axis grow a little bit. For example to the next rounded value. Or to be able to show the marker outside the rectangle of the graph.

Any help would be appreciated.

  • 26458
    Offline posted

    Hi,

    You have a few options here. Increasing the y axis range is simple enough to do, but to know how much to increase the range by you'll have to loop through your data and calculate the actual range. Let's say that the data ranges from 0 to 4. You would then set yAxis.maximum to something like 4.5. This works best if you always want to have that extra range padding, but can be tricky if you only want to pad the range in certain cases.

    If you're ok with the marker text spilling out of the plot area bounds, you can set options.displayAsImage = NO in your chartView:viewForMarkerInSeries: method. This tells the chart to show your labels (let's assume they're UILabels) as views instead of images, thus preventing clipping. Your text will be displayed above the column and the top gridline, provided it doesn't go out of bounds of the chart view.

    It's not uncommon to show the marker inside the column when there's not enough room at the top. You'll probably have to set a different contrasting background color to that label, but it would look something like this:

    if (options.markerLocation.y - label.bounds.size.height < options.viewportBounds.origin.y)
    {
       options.offsetY = label.bounds.size.height;
    }
    else
    {
       options.offsetY = - label.bounds.size.height;
    }

    Hopefully this helps you out.