简体   繁体   中英

Displaying flot PieChart from asp.net mvc json data

flot chart fails to display . There are no errors popping up when debugging. but same js display data for a sparkline chart. the data is in json format and looks like this. ..

[
  {
    "label": "Female",
    "data": 43
  },
  {
    "label": "Male",
    "data": 56
  }
]

while the actual js is like this ...

<script type="text/javascript">
    $(document).ready(function () {
        $('body').addClass('light-navbar');
            $.getJSON("../../Dashboard/getGuestGenderPieData")
            .done(function (data) {
                jQuery('#guestgenderpie').sparkline(data, {
                   type: 'pie',
                   height: '140',
                   sliceColors: ['#1ab394', '#F5F5F5']
            })
        });
    });        
</script>

Sparkline pie charts accepts data in the form at [24, 43, 33]. where each item in this array is a slice of the pie chart. if you must send data in the initial format, then you should use a flot pie chart and not a sparkline like this :

 $(document).ready(function () { $.plot($("#guestgenderpie"), data, { series: { pie: { show: true } }, legend: { labelBoxBorderColor: "none" } }); }); 
See more options at Flot pie charts

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM