gpt4 book ai didi

jquery - 自定义 Highcharts 的点弹出窗口

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

在这个 fiddle 中:

http://jsfiddle.net/LLExL/5122/

系列标签未正确显示。如果将鼠标悬停在数据点上,x 数据点将显示为以毫秒为单位的时间。

源代码:

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="chart-grid"></div>

.chart {
width: 350px;
height: 300px;
}

var json = [
{
"header": "test1",
"children": [
{
"date": "2015-01-02",
"count": "36"
},
{
"date": "2015-01-03",
"count": "29"
}
]
},
{
"header": "test2",
"children": [
{
"date": "2015-01-02",
"count": "36"
},
{
"date": "2015-01-03",
"count": "129"
}
]
}
];

$(document).ready(function () {

var options = {
chart: {
type: 'scatter'
},
title: {
text: 'test' // Title for the chart
},
subtitle: {},
legend: {
enabled: true
},
tooltip: {},
plotOptions: {
series: {
//pointStart: pointStart,
pointInterval: 24 * 3600 * 1000 * 30
}
},
xAxis: {

type: 'datetime'
},
yAxis: {
minPadding: 0,
maxPadding: 0,
gridLineColor: 'rgba(204,204,204,.25)',
gridLineWidth: 0.5,
title: {
text: 'Access Count',
rotation: 0,
textAlign: 'right',
style: {
color: 'rgba(0,0,0,.9)',
}
},
labels: {
style: {
color: 'rgba(0,0,0,.9)',
fontSize: '9px'
}
},
lineWidth: .5,
lineColor: 'rgba(0,0,0,.5)',
tickWidth: .5,
tickLength: 3,
tickColor: 'rgba(0,0,0,.75)'
},
series:[]
};

var $chartGrid = $('#chart-grid'),
title = [],
serie,
date,
name;

$.each(json, function(i, item) {
name = 'container-' + i;
$chartGrid.append('<div id="'+name+'" class="chart"></div>');

serie = [{
data: []
}];

$.each(item.children, function(j, points) {
date = points.date.split('-'); //Date.parse doens't work in FF and IE

serie[0].data.push({
x: Date.UTC(date[0],date[1],date[2]),
y: parseFloat(points.count)
});
});


options.title.text = item.header;
options.series = serie;
$('#' + name).highcharts($.extend({}, options));
});


});

如果我使用线图 http://jsfiddle.net/LLExL/5123/正在显示日期。

如何在悬停时显示格式为 dd/mm/yyyy hh:mm:ss 的 x 轴值?

弹出的 x 和 y 标签可以重命名吗?

最佳答案

您可以使用工具提示格式化程序选项和 Highcharts.dateFormat 来根据您的需要进行格式化。

tooltip: {
formatter: function () {
return 'x: ' + Highcharts.dateFormat('%d/%m/%Y %H:%M:%S', this.x) + '<br>' + 'y: ' + this.y;
}
},

http://jsfiddle.net/nicholasduffy/sm42x9u8/2/

http://api.highcharts.com/highcharts#tooltip.formatter http://api.highcharts.com/highcharts#Highcharts.dateFormat

关于jquery - 自定义 Highcharts 的点弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32288704/

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