0

I'm developing an iOS application and using shinobichart for iOS to display data. But I'm stuck with positioning the datapoints outside or inside the bar based on the bar frame.

I'm stuck in positioning the data point labels inside the bar or outside the bar based on bar frame. If bar is big enough to accommodate the data point I need to position the data point inside bar or else outside the bar as in the below image

Column chart with dynamic data point positioning

Bar chart with dynamic data point positioning

In - (void)sChart:(ShinobiChart *)chart alterDataPointLabel:(SChartDataPointLabel *)label forDataPoint:(SChartDataPoint *)dataPoint inSeries:(SChartSeries *)series we need to update data points if we wish as per shinobi documentation. But what logic can help to solve such an alignment of data points.

Also I tried to with the following official shinobi example to align data point aside https://www.shinobicontrols.com/blog/customizable-datapoint-labels But unable to modify for the requirement.

Please help to solve this riddle.

Chethan Shetty
  • 1,972
  • 4
  • 25
  • 45

1 Answers1

0

The best way for you to achieve this is to use the alterDataPointLabel method as you have mentioned. I would do something like this:

func sChart(chart: ShinobiChart!, alterDataPointLabel label: SChartDataPointLabel!, forDataPoint dataPoint: SChartDataPoint!, inSeries series: SChartSeries!) {
    if Int(label.text!) > [YOUR CUT OFF VALUE]
    {
        label.frame.origin.y += 15
        label.textColor = UIColor.whiteColor()
    }
    else
    {
        label.frame.origin.y -= 15
        label.textColor = UIColor.blackColor()
    }
}

This works best if you know the values your chart is going to be displayed. However as a more generic way of achieving it I would recommend comparing the y value of the data label's origin against y value of the chart canvas. Then for example you could set the it so it appears within the column if it the series was 90% of the canvas?

Matt W
  • 323
  • 3
  • 14