javascript - flot pie chart data with hh:mm format -


i have data flot pie chart in h:m format.

normally if give data in following format shows pie chart properly

var data = [     {label: "data1", data:10},     {label: "data2", data: 20},  ]; 

but if instead of int/double directly give data hh:mm format dont anything

var data = [     {label: "data1", data:10:30},     {label: "data2", data: 20:20},  ]; 

my question is without converting h:m plain int/double value there other way show h:m in flot pie chart?

if no conversion better this?

flot can not automatically unterstand time values, have convert them e.g. minutes. can use labelformatter function show values of pie slices in original format. this:

$(function () {     var data = [{         label: "data1",         data: '10:30'     }, {         label: "data2",         data: '20:20'     },      ];      (var = 0; < data.length; i++) {         var hours = parseint(data[i].data.split(':')[0]);         var minutes = parseint(data[i].data.split(':')[1]);         data[i].data = hours * 60 + minutes;     }      var plot = $.plot("#placeholder", data, {         series: {             pie: {                 show: true,                 label: {                     radius: 0.5,                     formatter: labelformatter                 }             }         },         grid: {             hoverable: true,             autohighlight: true         },         legend: {             show: false         }     });      function labelformatter(label, series) {         var value = math.floor(series.data[0][1] / 60) + ':' + (series.data[0][1] % 60);         return "<div style='font-size:10pt; text-align:center; padding:2px; color:black;'>" + label + "<br/>" + math.round(series.percent) + "%<br />" + value + "</div>";      }  }); 

see fiddle full example.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -