gpt4 book ai didi

jquery - Highcharts(基本折线图)与 x 轴相比可以有多个值吗?

转载 作者:行者123 更新时间:2023-12-01 01:14:44 28 4
gpt4 key购买 nike

我想制作一个 Highchart(基本折线图),它可以在 x 轴上具有多个值。

我正在尝试制作一个包含值(y 轴)与日期(x 轴)的折线图。问题是可能有多个值或特定日期。我是 Highcharts 的新手,但我浏览了 API,但没有找到一种方法来绘制具有多个值(在 y 轴上)与 x 轴图的图表。我希望日期采用“06july”格式。

这是我的代码:

 <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highcharts Example</title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#g1').highcharts({
chart:{
polar:true,
backgroundColor:'#E9BE51'


} ,title: {
text: 'Cholesterol',
x: -20 //center
},

xAxis: {
//categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']
//type: 'date'
},
yAxis: {
title: {
text: 'Value(mmol/L)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: 'in'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [ {
name: 'Total',
data: [{ name:'jan' , y:12} , {name:'jan' , y:8.2}, {name:'mar' , y:10.2} , {name:'apr' , y:14.5}]
}/*, {
name: 'LDL',
data: [['jan',3.9],[ 'feb', 4.2],['mar', 5.7],['apr', 8.5] ]
}, {
name: 'HDL',
data: [['jan',4.9], [ 'feb',4.0], ['mar',4.5],['apr', 6]]
}*/]
});
});





</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>


<div class="container" id="g1" style="width: 50%; height: 50%; margin: ; "></div>



</body>

最佳答案

要为单个 x 值设置多个 y 值,只需在制作系列时专门指定 x 值。对于行和日期时间的工作方式相同。

对于 type: 'line' 你可以这样做 ( JSFiddle ):

data: [[0, 7.0], [0, 10.0], 6.9, 9.5, 14.5, [3, 15.0], 18.2, 21.5, 25.2, 26.5, 23.3, [8, 10.0], 18.3, 13.9, 9.6]

对于类型:'datetime',您可以这样做( JSFiddle ):

data: [
...
[Date.UTC(1971, 1, 23), 0.77],
[Date.UTC(1971, 1, 23), 1.5],
...
]

并使用dateTimeLabelFormats以特定方式显示日期。请参阅this answer for format explanation 。代码可能是这样的( same JSFiddle above ):

dateTimeLabelFormats: {
month: '%d%B'
}

关于jquery - Highcharts(基本折线图)与 x 轴相比可以有多个值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25010320/

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