Set start and end point for both (x-y) axis in time series chart


#1

Hi 

I have just got the trial version of shinobi charts …sooner to buy it. But, right now i am confused with the automatic points set on the chart axis when it renders. Actually, i am buidling xamarin.ios app and want to show weight. I don’t want to show the line start from bottom to top , i want to show it like where the data entry is may be from the middle of the y axis. Could any one tell how could i achieve this.  Thanks


#2

Hi Bhupinder,

It sounds to me as though you are wanting to set the range of your Y-axis. When you create your Y-axis, use the initWithRange: constructor and provide a sensible range that will have your series placed where you want it. For example, if your weight data is around 100 lbs, you might want your range spanning from 0 to 200.

Jan


#3

Thanks Jan, it works fine . Another thing is on the x axis, I am showing date. I have three buttons on the top of the chart,(Week, One Month, Three Month). Could you suggest me how can i acheive this.  Right now i use this 

NSDateFormatter dateFormatter = new NSDateFormatter { DateFormat = "dd-MM-yyyy" };

            NSDate min_date = dateFormatter.Parse (“15-01-2013”);
            NSDate max_date = dateFormatter.Parse (“30-01-2013”);

            SChartDateRange range = new SChartDateRange (min_date,max_date);

            SChartDateTimeAxis xAxis = new SChartDateTimeAxis (range);

            xAxis.MajorTickFrequency = SChartDateFrequency.CreateWithDay (1);

            chart.XAxis = xAxis;

Thanks


#4

Hi Jan, any update on my last question ?


#5

Hi Bhupinder,

The approach you’re taking to set the range of the x axis looks sensible. Can I just clarify your use case? Would you like the buttons to set the maximum date on the x axis compared to the minimum date?

Having found your new minimum and maximum dates, you can set the range on the axis using the following method (I’ve copied in the method signature from the SChartAxis API):

/** Attempts to set the current visible range `axisRange` to a range with the given minimum and maximum values.
 
 Given any restrictions on setting the range, such as `allowPanningOutOfMaxRange` etc, this method will attempt to set the current axis range.
 
 @param minimum - the minimum value to be displayed, in data terms.
 @param maximum - the maximum value to be displayed, in data terms.
 @return Whether or not the operation was successful. 
 
 The permissable types of minimum and maximum will vary depending on the type of axis in use. The range of an `SChartNumberAxis` should be set using two objects of type `NSNumber` for `minimum` and `maximum`, whilst that of an `SChartDateTimeAxis` can be configured using either `NSNumber` or `NSDate` minima and maxima. In the case of `SChartCategoryAxis`, the first value has a nominal integer value of '0' and the nth value, 'n-1'.

 A few examples:
 
    // Range from 20 to 140 on an SChartNumberAxis.
    [myNumberAxis setRangeWithMinimum: @20 andMaximum: @140];
 
    // Range from June 2013 to January 2014 (approx.) on an SChartDateTimeAxis.
    [myDateTimeAxis setRangeWithMinimum: [NSDate dateWithTimeIntervalSince1970: 86400.*365*43.5] andMaximum: [NSDate dateWithTimeIntervalSince1970: 86400.*365*44]];
 
    // Range between the third and fifth elements on an SChartCategoryAxis.
    [myCategoryAxis setRangeWithMinimum: @2 andMaximum: @6];
 */
- (BOOL)setRangeWithMinimum:(id)minimum andMaximum:(id)maximum;

#6

HI Jan,

I need to display the date frequency on x-axis. Right now I display Like " 20 jan   24 Jan   28 Jan " but instead of this i want to display like " 20 jan 21 jan …"

with one day frequency depends upon the selection of buttons from the top of the chart. I will have One week(Current Week), One Month (Current Month) and 3 Month buttons . Just trying to figure out how can i acheive this.


#7

Hi Bhupinder,

You can set the “majorTickFrequency” on your xAxis to the value corresponding to the button pressed. Then redraw your chart like so:

yourChart.XAxis.MajorTickFrequency = SChartDateFrequency.CreateWithMonth (1);
yourChart.RedrawChart();

Let me know if you have any questions.

Kind Regards,
Andrew Polkinghorn


#8

H Andrew,

I tried MajorTickFrequency with createwithday(1) but it still shows four days difference. But, when i tap on the data point in the graph it zoom and shows one day diff ?


#9

I am not able to get it working with SChartDateFrequency.CreateWithDay(1). When i set to 1 it shows frequency of two days ?


#10

Were you calling RedrawChart after you used CreateWithDay()?


#11

Yes


#12

Hi Bhupinder,

I’m afraid if the chart can’t find enough room to fit in the tick labels it won’t. You either need to make your chart larger or change the format of the labels.

Hope this helps!

Rob