SChartAxis width property usage


#1

Hi there, hoping to get some help with how to use the width property of SChartAxis:

http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiCharts/2.1.1/Premium/Normal/Classes/SChartAxis.html#//api/name/width

I’d like to set this so that multiple charts all align, as stated in the docs. I’m assuming I set the value in points, similar to what you’d get back in frame.size.width.

However, when I do that, my entire series dissappears, and the x axes show at the top of the view, rather than towards the bottom.

Attaching screen shots below. Appreciate  any guidance.


#2

Hi Justin,

You nearly got it!

If you want all your charts to be lined up you need to set your charts Y-Axis width. This is due to your chart’s plot area width being calculated by subtracting your chart’s Y-Axis width from your chart’s frame.

Try setting your Y-axis width using the following code(where “desiredWidth” is set by you):

yourChart.yAxis.width = desiredWidth;

  Kind Regards,

Andrew Polkinghorn.


#3

Beautiful, that did the trick! Thank you, Andrew.

This post helped me understand that xAxis.width is actually expressed as a height (since the axis is lying on it’s side).


#4

Follow-up question: occasionally my yAxis disappears, and I get the following message:

Defaulting axis width, invalid value given

Width Value given:44

Width Value used:0 

What could make this value invalid?

Thanks!


#5

Also seeing this message: The size/layout of the ShinobiChart does not have sufficient room for laying out its elements, and may display incorrectly. Try disabling the chart legend, axis labels, axis titles, etc. or increasing the size of the chart itself

How can I disable the axis labels and titles?

Thank you -


#6

Hi Justin,

It sounds like your axis labels aren’t been given enough space. Do these errors keep appearing when you increase your Y-axis width ?

Kind Regards,

Andrew Polkinghorn


#7

Thanks for the response. Yes, even if I give them a lot more space than they should need, there are a couple that periodically disappear. I will investigate more and report back details.

I did find these to reduce things I don’t need (when I can do without them, but usually I need them):

    xAxis.style.majorTickStyle.showTicks = NO;

    xAxis.style.majorTickStyle.showLabels = NO;


#8

I figured out what was going on. At the time I set the axis width, the frame of the chart was smaller than it ended up eventually getting set in layoutSubviews. Takeaway is that you must set the axis after the frame of the chart is set to your intended size.


#9

Hi Justin

JustinKent

I figured out what was going on. At the time I set the axis width, the frame of the chart was smaller than it ended up eventually getting set in layoutSubviews. Takeaway is that you must set the axis after the frame of the chart is set to your intended size.

Do you have some more informations on how to do this?

Thx.

Cheers
Frank


#10

To diagnose, set a breakpoint where you’re setting the axis width. When the breakpoint gets hit, make sure the size of the chart is something that makes sense. If it’s very small, or zero, it may not actually be in the view hierarchy yet, and there’s your problem.

For instance, you can’t do this in init, it’s better to do it somewhere like viewDidLoad.

Something like this:

SChartNumberAxis *yAxis;
    SChartNumberRange *range = [[SChartNumberRange alloc] initWithMinimum:minY
                                                                         andMaximum:maxY];
    yAxis = [[SChartNumberAxis alloc] initWithRange:range];
    yAxis.width = [NSNumber numberWithInt:YAxisWidth];
    [self.chart addYAxis:yAxis];