Pie chart - handling negative values

5 posts, 0 answers
  1. MRa
    MRa avatar
    16 posts
    Member since:
    Dec 2012

    Posted 09 Jan 2013 Link to this post

    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"
                        }
                    });
  2. Hristo Germanov
    Admin
    Hristo Germanov avatar
    703 posts

    Posted 10 Jan 2013 Link to this post

    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!
  3. MRa
    MRa avatar
    16 posts
    Member since:
    Dec 2012

    Posted 10 Jan 2013 Link to this post

    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!
  4. Hristo Germanov
    Admin
    Hristo Germanov avatar
    703 posts

    Posted 11 Jan 2013 Link to this post

    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!
  5. MRa
    MRa avatar
    16 posts
    Member since:
    Dec 2012

    Posted 11 Jan 2013 Link to this post

    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!
Back to Top