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

Pie chart - handling negative values

4 Answers 333 Views
Charts
This is a migrated thread and some comments may be shown as answers.
MRa
Top achievements
Rank 1
MRa asked on 09 Jan 2013, 08:02 PM
The pie chart does not seem to be able to handle negative values, the graph distorts completely if a negative value is introduced. Any way around this?

Sample data below:

   var data_by_location = [
                          { "location": "IN", "year": 2012, "month": 1, "revenue": 18228 },
                          { "location": "TX", "year": 2012, "month": 1, "revenue": 15014 },
                          { "location": "KY", "year": 2012, "month": 1, "revenue": 16898 },
                          { "location": "MI", "year": 2012, "month": 1, "revenue": 12186 },
                          { "location": "CA", "year": 2012, "month": 1, "revenue": -9945 }
                          ]

I'm including the code for the pie chart below but everything is pretty standard:

  $(document).ready(function () {
                $("#piechart").kendoChart({
                    dataSource: data_by_location,
                    seriesDefaults: {
                        type: "pie",
                        labels: {
                            visible: true,
                            template: "#= category # - #=kendo.format('{0:p}', percentage) # "
                                 }
                    },
                    title: {
                        text: "Monthly Revenue per Location"
                    },
                    legend: {
                        position: "bottom"
                    },
                    series: [{
                        field: "revenue",
                        categoryField: "location"
                    }],
                    tooltip: {
                        visible: true,
                        format: "N0"
                    }
                });

4 Answers, 1 is accepted

Sort by
0
Hristo Germanov
Telerik team
answered on 10 Jan 2013, 09:30 AM
Hi Mery,

I am not sure what we should do in this case.

Could you tell me what you have expected to happen with the pie chart?

All the best,
Hristo Germanov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
MRa
Top achievements
Rank 1
answered on 10 Jan 2013, 02:40 PM
Usually what excel does is it will use the absoluate value of the negative number, any way i can use a series template so the graph will use the absolute value of the field?
Thanks!
0
Hristo Germanov
Telerik team
answered on 11 Jan 2013, 09:07 AM
Hi Mery,

Thank you for your suggestion.

We will definetly consider it for our future releases. Until then you can use something like this: http://jsbin.com/uwacun/2/edit

All the best,
Hristo Germanov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
MRa
Top achievements
Rank 1
answered on 11 Jan 2013, 03:20 PM
Hi Hristo,

After further testing, i believe the kendo pie chart is able to handle negative and positive values out of the box. What's causing the problem in this case is the data itself. I'm currently using "unrefined" data (for testing purposes) that consists of really large negative numbers to really large positive numbers. The values in my data are the following:
-5,455
-95,622
-4,111,955
1,225,783
22,205,489
-57
0
0

If i switch some of the values to numbers like the ones listed below (reduce the largest negative number) the graph behaves fine:
-5,455
-95,622
-411,195
1,225,783
22,205,489
-57
0
0

From what i've seen the problem only happens when the data array consists of both really large positive and negative numbers, i did not see any problems when i tried only large positive or only large negative numbers.

This can be fixed on my end by doing some data refining/cleaning, please keep this in mind on further releases.

Thanks!
Tags
Charts
Asked by
MRa
Top achievements
Rank 1
Answers by
Hristo Germanov
Telerik team
MRa
Top achievements
Rank 1
Share this question
or