0

I'm using Shinobi iOS control for drawing line charts in my app. I'm currently rendering a serious of 0s value. The resulting graph is like that:

enter image description here

Now, the problem is that the quantity I'm representing is a currency so it cannot be negative. How can I limit the range to start from 0 in this specific case?

This is how I create the graph:

    // initiatialise line chart
    ShinobiChart *chartView = [[ShinobiChart alloc]initWithFrame:frame];
    chartView.clipsToBounds = NO;
    //Choose the light theme for this chart
    SChartLightTheme *theme = [SChartLightTheme new];
    //perform any theme stylign here before applying to the chart
    chartView.theme = theme;
    chartView.title = @"my Title"; 
    chartView.autoresizingMask = UIViewAutoresizingNone;
    // Use a number axis for the x axis.
    SChartDateTimeAxis *xAxis = [[SChartDateTimeAxis alloc] init];
    xAxis.title = @"date";
    xAxis.tickLabelClippingModeHigh = SChartTickLabelClippingModeTicksAndLabelsPersist;
 //keep tick marks at the right end
    //Make some space at the axis limits to prevent clipping of the datapoints
    xAxis.rangePaddingHigh = [SChartDateFrequency dateFrequencyWithDay:1];
    xAxis.rangePaddingLow = [SChartDateFrequency dateFrequencyWithDay:1];
    //allow zooming and panning
    xAxis.enableGesturePanning = YES;
    xAxis.enableGestureZooming = YES;
    xAxis.enableMomentumPanning = YES;
    xAxis.enableMomentumZooming = YES;
    chartView.xAxis = xAxis;
    // Use a number axis for the y axis.
    SChartNumberAxis *yAxis = [[SChartNumberAxis alloc] init];
    yAxis.title = @"Value";
    yAxis.enableGesturePanning = YES;
    yAxis.enableGestureZooming = YES;
    yAxis.enableMomentumPanning = YES;
    yAxis.enableMomentumZooming = YES;
    yAxis.title = @"Value";
    yAxis.style.titleStyle.position = SChartTitlePositionBottomOrLeft;
    chartView.yAxis = yAxis;
    chartView.userInteractionEnabled = YES;
    chartView.gesturePanType = SChartGesturePanTypeNone;
Claus
  • 5,662
  • 10
  • 77
  • 118
  • I'm using a simple ShinobiChart subclass. Generally the range is always between thew lowest and the highest value. Now it makes sense for the graph to react like this because no extreme are provided in this case but I would prefer to set the lowest extreme to 0. – Claus Aug 06 '13 at 14:59
  • you're right...done :) – Claus Aug 06 '13 at 15:09
  • When you init the yAxis SChartNumberAxis you could try using the initWithRange: instance method with an appropriate SChartNumberRange. – John Parker Aug 06 '13 at 15:20
  • yes,I'm trying right now but I don't want to set statically the top value because that should be defined by my dataset. Also I might have negative values at some point. I would like to have a [0,max_value] range when the dataset contains only positive value and a [0,5] range when values are all zero. – Claus Aug 06 '13 at 15:23
  • You may need to get the high/low values from your dataset first (if indeed this approach works). – John Parker Aug 06 '13 at 15:24
  • yes..I think the only solution is to analyse the dataset before generating the graph but it's quite annoying. I was hoping in some properties I could use for handling those cases. – Claus Aug 06 '13 at 15:26
  • Let me know if this solves the issue and I'll write up an answer/cull the previous comments. – John Parker Aug 06 '13 at 15:32
  • If you let the chart render, you can use the [dataRange](http://www.shinobicontrols.com/docs/ShinobiControls/ShinobiCharts/2.2.1/Standard/Normal/Classes/SChartAxis.html#//api/name/dataRange) property rather than analysing your entire dataset. Then you can just set the range & redraw the chart. (An extra redraw won't affect performance.) – jaker Aug 12 '13 at 10:26

1 Answers1

0

yAxis.anchorPoint = @0;

Set this and it should solve your issue.

Rajesh
  • 850
  • 9
  • 18