绘制垂直线和水平带
Draw vertical lines and horizontal bands
我直接将数组绘制到我的高图表系列。我需要将 x 轴上的垂直线和 y 轴上的水平带显示为不同的颜色。
需要根据图表中显示的值添加垂直线和水平条。
这是我的代码:
$('#container').highcharts({
title: {
text: 'Graph',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
credits: {
enabled: false
},
colors: ['red'],
xAxis: {
// categories: [],
title: {
text: 'Time'
},
},
yAxis: {
title: {
text: 'Rate'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: ''
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
name: 'Heart Rate',
data: data_arr
}]
});
为此
,您可以使用chart.xAxis[0].categories.length
来访问xAxis的长度,chart.xAxis[0].categories[]
来访问xAxis元素的值。检查以下示例:
$(function() {
$('#container').highcharts({
xAxis: {
categories: [10, 20, 30, 40, 50, 60, 70]
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6]
}]
});
// the button action
var hasPlotLine = false,
$button = $('#button'),
chart = $('#container').highcharts();
$button.click(function() {
for (i = 1; i < chart.xAxis[0].categories.length; i++) {
if (chart.xAxis[0].categories[i] > 30) {
chart.xAxis[0].addPlotLine({
value: i,
color: 'red',
width: 2,
id: 'plot-line-1'
});
}
}
});
});
要设置垂直/水平线/波段,请使用 plotBands 或/和 plotLines 选项:
对于线条:
plotLines: [{
color: '#FF0000',
width: 2,
value: 5.5
}]
对于乐队
plotBands: [{ // mark the weekend
color: '#FCFFC5',
from: Date.UTC(2010, 0, 2),
to: Date.UTC(2010, 0, 4)
}],
您可以在此处阅读更多内容:
http://api.highcharts.com/highcharts#xAxis.plotBandshttp://api.highcharts.com/highcharts#xAxis.plotLines
检查以下示例 jsfiddle
$(function() {
$('#container').highcharts({
title: {
text: 'Graph',
x: -20 //center
},
subtitle: {
text: '',
x: -20
},
credits: {
enabled: false
},
colors: ['red'],
xAxis: {
// categories: [],
title: {
text: 'Time'
},
plotLines: [{
color: 'blue',
width: 1,
value: 1,
dashStyle: 'longdashdot',
zIndex: 3
}, {
color: 'blue',
width: 1,
value: 2,
dashStyle: 'longdashdot',
zIndex: 3
}, {
color: 'blue',
width: 1,
value: 3,
dashStyle: 'longdashdot',
zIndex: 3
}],
zIndex: 3,
},
yAxis: {
title: {
text: 'Rate'
},
plotBands: [{ // mark the weekend
color: '#BEE9B4',
from: 1,
to: 4
}, { // mark the weekend
color: '#EB813B',
from: 4,
to: 6
}, { // mark the weekend
color: '#E93A0F',
from: 6,
to: 8
}],
zIndex: 2,
},
tooltip: {
valueSuffix: ''
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
plotOptions: {
series: {
marker: {
enabled: false
}
}
},
series: [{
type: 'spline',
name: 'Heart Rate',
data: [4, 5, 1, 2, 8, 7, 4, 1]
}]
});
});
相关文章:
- 允许表单元格内容水平展开
- 如何在c3js动态图表上进行平滑(水平)转换
- 如何创建一个具有固定左右列和水平滚动的表
- 通过水平滚动将页眉固定到页面顶部
- 水平视差滚动从头开始-没有插件(jQuery)
- 具有Twitter引导程序的水平滚动表
- 如何避免鼠标水平滚动选项卡面板溢出
- 使用CSS嵌入HTML中的水平居中jQuery
- 如何使用Jquery水平打印表中的数组元素,并在某个元素之后垂直打印
- CSS堆栈角度重复水平而非垂直
- 制作水平滑动段
- Wordpress 3级水平导航-需要jquery/javascript帮助进行对齐
- 使用鼠标滚轮水平滚动页面
- 水平滚动不适用于jquery单击
- 如何实现水平页面导航系统
- 每次单击按钮时水平滚动元素
- 动画滚动100%(水平)
- 简单的一页水平滚动
- Pinterest样式布局与CSS,但水平堆叠而不是垂直堆叠
- 绘制垂直线和水平带