seb*_*oka 5 javascript json chart.js chart.js2 chartjs-2.6.0
当您将鼠标悬停在折线图上时,工具提示会从x轴显示错误的标签值。我正在使用最新版本的Chart.JS 2.8.0
这是小提琴:https : //jsfiddle.net/2mq1vt0o/
这是来自显示的数据集的所有数据:https : //imgur.com/a/EMbiejk
当我更改数据范围时,例如从05-01-2018 https://imgur.com/a/SXr6ymv
如您所见,该行在正确的位置,但是当我将鼠标悬停在该点上时,它会显示一个标签,这是标签中的第一个值,这是错误的,因为它应该显示06-01-2018。
{
"data": {
"datasets": [
{
"borderColor": "rgba(74,118,12,1.000)",
"data": [
{
"x": "2018-01-06",
"y": 0.242
},
{
"x": "2018-01-07",
"y": 0.197
},
{
"x": "2018-01-08",
"y": 0.15
},
{
"x": "2018-01-09",
"y": 0.15
},
{
"x": "2018-01-10",
"y": 0.15
},
{
"x": "2018-01-11",
"y": 0.137
},
{
"x": "2018-01-12",
"y": 0.11
},
{
"x": "2018-01-13",
"y": 0.11
},
{
"x": "2018-01-14",
"y": 0.21
},
{
"x": "2018-01-15",
"y": 0.273
},
{
"x": "2018-01-16",
"y": 0.3
},
{
"x": "2018-01-17",
"y": 0.237
}
],
"label": "onlydoe",
"fill": false,
"pointRadius": 5
}
],
"labels": [
"2018-01-05",
"2018-01-06",
"2018-01-07",
"2018-01-08",
"2018-01-09",
"2018-01-10",
"2018-01-11",
"2018-01-12",
"2018-01-13",
"2018-01-14",
"2018-01-15",
"2018-01-16",
"2018-01-17"
]
},
"options": {
"hover": {
"mode": "x"
}
},
"type": "line"
}
Run Code Online (Sandbox Code Playgroud)
我希望将鼠标悬停在某个点上时会显示正确的X轴值。
小智 2
好吧,我认为这是因为您没有指定 xAxis 类型,因此请尝试将其添加到您的选项中:
"scales": {
xAxes: [{
type: "time"
}]
}
Run Code Online (Sandbox Code Playgroud)
这是一个示例(https://jsfiddle.net/z8xLspd7/1/):
如果您想将鼠标悬停在该点时出现的时间值设置为更加用户友好的格式,只需将其添加到您的选项中:
responsive:true,
"scales": {
xAxes: [{
type: "time",
time:{
format: timeFormat,
tooltipFormat: 'll'
},
scaleLabel: {
display: true,
labelString: 'Date'
}
}]
}
Run Code Online (Sandbox Code Playgroud)
这是一个示例(https://jsfiddle.net/z8xLspd7/2/):
参考: https: //embed.plnkr.co/JOI1fpgWIS0lvTeLUxUp/
| 归档时间: |
|
| 查看次数: |
292 次 |
| 最近记录: |