Sushant Aryal
Sushant Aryal

Reputation: 3335

Flot pie chart series name "undefined"

I am trying to display browser visits for my site using flot pie chart. Everything is working properly except the series name displays as undefined. Data for the series is.

[

    [
        "Chrome",
        "54"
    ],
    [
        "Firefox",
        "51"
    ],
    [
        "Internet Explorer",
        "9"
    ],
    [
        "Opera Mini",
        "2"
    ],
    [
        "Safari",
        "2"
    ]

]

and the JavaScript is

$('#browserVisits').css({
    height: '300px',
    width: '100%'
});

$.plot($('#browserVisits'), visits, {
    series: {
        pie: {
            show: true
        }
    },
    grid: {
        hoverable: true,
        clickable: true
    },
    legend: {
        show: false
    }
});

And the result for this series is like Pie Chart

Why the series name displays undefined instead of browser name? What am I doing wrong and what can be the solution? Thanks.

Upvotes: 0

Views: 680

Answers (1)

Somnath Sarode
Somnath Sarode

Reputation: 477

Well you just have to add formatter function in pie block as follows

label: {
                 show: true,
                 formatter: function(label,point){
                     return(point.label + '<br>'+ point.percent.toFixed(2) + '%');

                 }
             }

Also i have created a sample fiddle for you take a look http://jsfiddle.net/coolbhushans/03kd2mav/

Upvotes: 2

Related Questions