我使用razor语法将数据设置为高图:
series: [
@foreach (var item in Model)
{
<text>
{
name: '@item.name',
data: [
@foreach (var item2 in item.finalChart)
{
@:[Date.parse("@item2.date1"), @item2.value],
}
]
},
</text>
}
]
这里执行代码:
series: [
{
name: 'clicks6',
data: [
[Date.parse("04/03/2017"), 10],
[Date.parse("04/04/2017"), 45],
]
},
{
name: 'clicks4',
data: [
[Date.parse("04/03/2017"), 28],
[Date.parse("04/04/2017"), 22],
]
},
{
name: 'clicks8',
data: [
[Date.parse("04/03/2017"), 8],
[Date.parse("04/04/2017"), 35],
[Date.parse("04/05/2017"), 5],
[Date.parse("04/10/2017"), 0],
]
},
]
正如您在下面的点中看到的那样,不适合y
轴。
如果我添加其他格式的数据,则此问题不会发生
series: [{
name: 'Installation',
data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
},{
name: 'Other',
data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
}]
如何解决这个问题?由于某些原因,我无法使用其他格式的数据。
答案 0 :(得分:1)
将UTC
添加到每个日期输入Date.parse("04/03/2017" + ' UTC')
@:[Date.parse("@item2.date1" + ' UTC'), @item2.value],
xAxis将是
xAxis: {
type: 'datetime',
tickInterval: 24 * 3600 * 1000 //this is for one day
},
Highcharts.chart('container', {
chart: {
type: 'spline',
zoomType: 'x'
},
title: {
text: 'Highcharts'
},
subtitle: {
text: document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
},
xAxis: {
type: 'datetime',
tickInterval: 24 * 3600 * 1000
},
yAxis: {
title: {
text: 'Snow Depth'
},
},
series: [{
name: 'clicks6',
data: [
[Date.parse("04/03/2017" + ' UTC'), 10],
[Date.parse("04/04/2017" + ' UTC'), 45],
]
},
{
name: 'clicks4',
data: [
[Date.parse("04/03/2017" + ' UTC'), 28],
[Date.parse("04/04/2017" + ' UTC'), 22],
]
},
{
name: 'clicks8',
data: [
[Date.parse("04/03/2017" + ' UTC'), 8],
[Date.parse("04/04/2017" + ' UTC'), 35],
[Date.parse("04/05/2017" + ' UTC'), 5],
[Date.parse("04/10/2017" + ' UTC'), 0],
]
},
]
});
&#13;
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
&#13;