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
Post a Comment