Search code examples
javascriptjqueryjqplot

jQPlot charts- Pie chart disappears on passing high values


When i run the code the chart disappears

$(document).ready(function(){

    var d1=${views};
    var d2=${comoneviews};
    var d3=${comtwoviews};
    var plot1 = $.jqplot('piechart', [[['Your Organisation',d1],['Competitor#1',d2],['Competitor#2',d3]]], {
        gridPadding: {top:0, bottom:38, left:0, right:0},
        seriesDefaults:{
            renderer:$.jqplot.PieRenderer, 
            trendline:{ show:false }, 
            rendererOptions: { padding: 7, showDataLabels: true ,  dataLabels: 'value'}
        },
        legend:{
            show:true, 
            placement: 'outside', 
            rendererOptions: {
                numberRows: 1
            }, 
            location:'s',
            marginTop: '15px'
        }       
    }); 
});

the input values i am getting for d1 is 20700000 , d2 is 2300000, and d3 is 3040000. So does the chart does not appear because of higher values?


Solution

  • Per your comment, you just need to refer to the d1,d2 and d3 array values correctly. As you've mentioned, you are getting them as arrays - so the problem must be with your access to the actual values.

    Access them as d1[0] d2[0] d3[0] (assuming you have a one sized array like you wrote)

    var d1=[20700000];
    var d2=[2300000];
    var d3=[3040000];
    var plot1 = $.jqplot('piechart', [[['Your Organisation',d1[0]],
    ['Competitor#1',d2[0]],['Competitor#2',d3[0]]]], {
         ...rest of plot code...
    

    here is a working example with d1-d3 modified to arrays.