gpt4 book ai didi

javascript - Highcharts 显示当月数据与周间隔

转载 作者:行者123 更新时间:2023-12-03 01:03:13 30 4
gpt4 key购买 nike

我正在使用 highchart 折线图以每周间隔显示当月数据。但图表线条未显示这是我的代码:

    $(function () {
$('#container').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
type: 'datetime',
min : Date.UTC(2015, 8, 1),
max: Date.UTC(2015, 8, 30),
dateTimeLabelFormats: {
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
tickInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
},
yAxis: [{ // left y axis
title: {
text: null
},
labels: {
align: 'left',
x: 3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}, { // right y axis
linkedTo: 0,
gridLineWidth: 0,
opposite: true,
title: {
text: null
},
labels: {
align: 'right',
x: -3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}],
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
legend: {
align: 'left',
verticalAlign: 'top',
borderWidth: 0
},

/* plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0,
groupPadding: 0.1,
//pointStart: Date.UTC(2015, 1, 12) // feb 12, 2015
}
}, */

plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function (e) {
hs.htmlExpand(null, {
pageOrigin: {
x: e.pageX || e.clientX,
y: e.pageY || e.clientY
},
headingText: this.series.name,
maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) + ':<br/> ' +
this.y + ' sessions',
width: 200
});
}
}
},
marker: {
lineWidth: 1
}
}
},

series: [{
name: 'Tokyo',
data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
pointStart: Date.UTC(2015, 1, 12),
pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day

},
{
name: 'New York',
data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3],
pointStart: Date.UTC(2015, 1, 12),
pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day

}, {
name: 'London',
data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2],
pointStart: Date.UTC(2015, 1, 12),
pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
}, {
name: 'Berlin',
data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1],
pointStart: Date.UTC(2015, 1, 12),
pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
}
]
});
});

任何人都可以建议任何解决方案来显示当月与周间隔的折线图中的点。我需要像这个 Highcharts 示例那样的周间隔 https://www.highcharts.com/demo/line-ajax .

最佳答案

您已将 xAxistickInterval 设置为从 Date.UTC(2015, 8, 1) 的 7 天Date.UTC(2015, 8, 30) 但设置seriespointStartDate.UTC(2015, 1, 12)开始.

因此只需将 pointStart 更改为 Date.UTC(2015, 8, 1)

顺便说一句,7 * 24 * 3600 * 1000 是 7 天。

(7 天 * 每天小时数 * 每小时秒数 * 每秒毫秒数)

$(function() {
$('#container').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Monthly Average Rainfall'
},
subtitle: {
text: 'Source: WorldClimate.com'
},
xAxis: {
type: 'datetime',
gridLineWidth: 1,
min: Date.UTC(2015, 8, 1),
max: Date.UTC(2015, 8, 30),
dateTimeLabelFormats: {
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
tickInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
},
yAxis: [{ // left y axis
title: {
text: null
},
labels: {
align: 'left',
x: 3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}, { // right y axis
linkedTo: 0,
gridLineWidth: 0,
opposite: true,
title: {
text: null
},
labels: {
align: 'right',
x: -3,
y: 16,
format: '{value:.,0f}'
},
showFirstLabel: false
}],
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
legend: {
align: 'left',
verticalAlign: 'top',
borderWidth: 0
},

/* plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0,
groupPadding: 0.1,
//pointStart: Date.UTC(2015, 1, 12) // feb 12, 2015
}
}, */

plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function(e) {
hs.htmlExpand(null, {
pageOrigin: {
x: e.pageX || e.clientX,
y: e.pageY || e.clientY
},
headingText: this.series.name,
maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) + ':<br/> ' +
this.y + ' sessions',
width: 200
});
}
}
},
marker: {
lineWidth: 1
}
}
},

series: [{
name: 'Tokyo',
data: [
[Date.UTC(2015, 8, 1), 49.9],
[Date.UTC(2015, 8, 3), 71.5],
[Date.UTC(2015, 8, 5), 106.4],
[Date.UTC(2015, 8, 7), 129.2],
[Date.UTC(2015, 8, 9), 144.0],
[Date.UTC(2015, 8, 12), 176.0],
[Date.UTC(2015, 8, 15), 135.6],
[Date.UTC(2015, 8, 18), 148.5],
[Date.UTC(2015, 8, 21), 216.4],
[Date.UTC(2015, 8, 24), 194.1],
[Date.UTC(2015, 8, 27), 95.6],
[Date.UTC(2015, 8, 30), 54.4]
],

},
{
name: 'New York',
data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3],
pointStart: Date.UTC(2015, 8, 1),
pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day

}, {
name: 'London',
data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2],
pointStart: Date.UTC(2015, 8, 1),
pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
}, {
name: 'Berlin',
data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1],
pointStart: Date.UTC(2015, 8, 1),
pointInterval: 7 * 24 * 3600 * 1000 // interval of 1 day
}
]
});
});
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

关于javascript - Highcharts 显示当月数据与周间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52529453/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com