ShinobiCharts - Donut series plot area

173 Views Asked by At

In a UIViewController (think of an iPad landscape layout) I'm displaying 3 charts (one beside the other) with a donut series each and their legend displayed on bottom middle, outside the plot area, the views containing the charts are of the same size.

Each chart shows up to 5 values, so when they have the same number of values all the donuts and legends appear perfectly aligned with each other.

The problem is that when one of the charts has fewer values, the legend takes a smaller vertical space therefore making the donut appear lower than the others.

Is there a way to fix the plot area at a certain size? My goal would be making all the donuts and legends appear aligned regardless of the number of values for each series.

Thanks!

2

There are 2 best solutions below

0
On BEST ANSWER

Starting from MrAPolk answer, I managed to implement a solution to my problem.

These are the steps I followed:

  1. In Interface Builder, for each of my charts I drew the chart container UIView with the adequate size to contain only the donut; then I drew another UIView as legend container, placed below the chart container.
  2. In the chart setup, I style the legend to my needs and set it as hidden (chart.legend.hidden = YES;).
  3. I implemented the SChartDelegate method sChartRenderFinished: to do something like this:

    - (void)sChartRenderFinished:(ShinobiChart *)chart {
        SChartLegend *legend = chart.legend;
        [legend removeFromSuperview];
        legend.hidden = NO;
        legend.frame = legendContainer.bounds; //legendContainer is the UIView defined in IB
        [legendContainer addSubview:legend];
        [legend setNeedsDisplay];
    }
    

MrAPolk's answer didn't actually solve my problem, but it sparkled this solution, so I would give him +1 if I could.

1
On

DISCLAIMER I am a developer at Shinobi Controls.

If you provide your legend with a frame the chart won't resize it's canvas to fit both the legend and canvas inside the your chart's frame.

This means you can position your legend where you want and the chart won't resize it's canvas depending on the size of the legend.

This may mean you need to give your chart a smaller initial frame so you can fit your legend in beside your chart.

If you have any questions don't hesitate to get in touch!

Kind regards, Andrew Polkinghorn.