This is a migrated thread and some comments may be shown as answers.

Showing Negative and Positive Values in Line or Area Charts

3 Answers 275 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sal
Top achievements
Rank 1
Sal asked on 31 Aug 2015, 08:58 PM

I have two questions, the first being if there's a way to show negative and positive values on the same chart ((I'm trying to show daily transaction details so some days will have negative values and others will have positive values). I don't know if it's due to how I setup the datapoint (I'm just passing the number over as a string so maybe I need to convert it to a float or int value) or if it's something extra I need to do when setting up the axes. 

 

The second question is in regards to the y-axes, I only want to show the lowest and highest point of the chart (so I don't have a long series of labels as in the screenshot below at after a couple weeks). I don't know if it's due to the amount of labels that are being show but as more data is added the chart itself starts to get smaller and pushed further to the right hand side of my view, where when I have just a few points in fills in the whole view. I am using the newest version of the Telerik controls as well just in case anyone thinks that's an issue. 

3 Answers, 1 is accepted

Sort by
0
Sophi
Telerik team
answered on 01 Sep 2015, 08:32 AM
Hello Sal,
Thank you for contacting us.

Yes, there is a way to show negative and positive value on the same axis. You should use TKChartNumericAxis and the values of your TKChartDataPoint should be NSNumbers. The axis will arrange the numbers in the correct order.
TKChartNumericAxis *yAxis = [[TKChartNumericAxis alloc] init];
_chart.yAxis = yAxis;

On your second question, you can manipulate the shown value interval and the size of the ticks of the axes.
You should use majorTickInterval property to change the distance between the shown points. The code below results in showing the data points on the xAxis with interval of 20.
TKChartNumericAxis *xAxis = [[TKChartNumericAxis alloc] init];
xAxis.majorTickInterval = @20;
_chart.xAxis = xAxis;

In order to show only specific interval of your axis you should initialize it with minimum and maximum:
TKChartNumericAxis *yAxis = [[TKChartNumericAxis alloc] initWithMinimum:@(-100) andMaximum:@(100)];

I hope this helps. If you have any other questions, do not hesitate to contact us.

Regards,
Sophi
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Sal
Top achievements
Rank 1
answered on 01 Sep 2015, 05:28 PM
Thanks Sophi, the first issue was fixed by formatting the datapoint to a NSNumber and using the ChartNumericAxis but let me clarify the second issue a little bit more. I'm not worried about the range that is used, what I want to do is only show the minimum and maximum label, while the rest of the labels for all the other majorTicks is blank/hidden. Is there a way to do this or do I need to adopt a delegate method and go through each one hiding the ones I don't want to display? 
0
Sophi
Telerik team
answered on 02 Sep 2015, 10:45 AM
Hi Sal,

The easiest way to do this is by setting the majorTickInterval property of the axis. It controls the interval used to place axis ticks. Here is an example:
TKChartNumericAxis *axis = (TKChartNumericAxis*)_chart.xAxis;
axis.majorTickInterval = @([axis.range.maximum doubleValue] - [axis.range.minimum doubleValue]);

As you suggested, another option is adopting TKChartDelegate and implementing the chart:textForAxis:value:atIndex: method that will allow you to iterate over axis labels and return empty text for the ones you do not need. Consider the following snippet:
-(NSString *)chart:(TKChart *)chart textForAxis:(TKChartAxis *)axis value:(id)value atIndex:(NSUInteger)index
{
    if ([axis isKindOfClass:[TKChartNumericAxis class]]){
        if (index == 0 || index == maximumIndex)
        {
            NSNumber *n = (NSNumber*)value;
            return [NSString stringWithFormat:@"%@",n];
        }
         
        return @"";
    }
    return value;
}

I hope this covers your case.

Regards,
Sophi
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
Sal
Top achievements
Rank 1
Answers by
Sophi
Telerik team
Sal
Top achievements
Rank 1
Share this question
or