Search code examples
iosobjective-cchartsdonut-chartshinobi

ShinobiCharts - Donut series plot area


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!


Solution

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