asp.net mvc 4 - How to bind model list variable to highchart -


@model list<monitoring>  <script>     function drawawsinstancesmonitoring() {         var seriesdata = [];         @foreach (var item in model)         {             seriesdata.push([date.parse(new date(parseint((item.sampledatetime).substr(6)))), item.percentused]);         }         $('#chart_monitoring').highcharts('stockchart', {             rangeselector: {                 selected: 1,                 inputenabled: false             },             title: { text: 'utilization' },             yaxis: { type: 'double', min: 0 },             xaxis: {                 type: 'datetime',                 labels: {                     formatter: function () { return highcharts.dateformat('%a %d %b %h:%m', this.value); },                     datetimelabelformats: {                         minute: '%h:%m',                         hour: '%h:%m',                         day: '%e. %b',                         week: '%e. %b',                         month: '%b \'%y',                         year: '%y'                     }                 }             },             series: [{                 name: 'usage',                 data: seriesdata,                 tooltip: {                     valuedecimals: 2                 }             }]         });     } </script> 

html

<div id="chart_monitoring" class="col-sm-12" style="height: 350px;"></div>` 

how bind directly model highchart ?

you can not use server variable in js. need parse model in json

var model = '@html.raw(json.encode(model))';             var data = json.parse(model);             var seriesdata = [];             (i = 0; < data.length; i++) {                 seriesdata.push([date.parse(new date(parseint((data[i].sampledatetime).substr(6)))), data[i].percentused]);             } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -