【发布时间】:2016-07-11 13:27:44
【问题描述】:
我使用 Highcharts 创建了一个图表,带有自定义标签来解释图表的详细信息。
现在,如果我将鼠标悬停在任何项目(例如条形图、柱形图)上,则应突出显示或选中相应的自定义标签。
下面是我图表的代码,
$(function () {
$('#ao-projectssummry-chart').highcharts({
chart: {
type: "columnrange",
inverted : true
},
title: { text: null },
credits: { enabled: false },
legend: { enabled: false },
tooltip: {
formatter: function() {
return '<b>' + this.series.name +'</b><br/>' +
Highcharts.dateFormat('%e - %b',
new Date(this.x)) ;
}
},
yAxis: {
opposite: true,
title : null,
crosshair: {
width: 2,
color: "#F26C6D",
snap: true,
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' +
Highcharts.dateFormat('%a - %a - %y', new Date(this.x));
}
},
gridLineWidth: 1,
gridZIndex: 0,
type: 'datetime',
min: Date.UTC(2016, 0, 1),
max: Date.UTC(2016, 11, 31),
},
xAxis: {
categories: ['Set up', 'Quantification of Benefit', 'Execute', 'Deploy to Pilot Stores', 'Full Deployment', 'Roll out to Production'],
min: 0,
max: 5,
title: null,
gridLineWidth: 1,
gridZIndex: 0,
labels:
{
enabled: false
},
crosshair: {
snap: true
}
},
plotOptions: {
series: {
pointWidth: 10,
borderRadius: 0,
marker: {
enbled : false
}
},
line: {
lineWidth:-1,
marker: {
enabled: true,
radius:0,
symbol: 'circle'
}
}
},
series: [
{
name: "Project Tire Sale",
data: [
{
x: 0.40,
low: Date.UTC(2016,0,15),
high: Date.UTC(2016,2,15),
color: "#60B3D1"
},
{
x: 0.40,
low: Date.UTC(2016,2,15),
high: Date.UTC(2016,4,24),
color: "#60B3D1"
},
{
x: 0.40,
low: Date.UTC(2016,4,7),
high: Date.UTC(2016,6,15),
color: "#9CCB01"
}
,
{
x: 0.40,
low: Date.UTC(2016, 6, 7),
high: Date.UTC(2016, 8, 15),
color: "#9CCB01"
},
{
x: 0.40,
low: Date.UTC(2016, 8, 7),
high: Date.UTC(2016, 10, 15),
color: "#9CCB01"
}
]
},
{
name: 'Project Tire Sale',
type: 'line',
data: [
{
x: 0.40,
y: Date.UTC(2016,2,15),
marker: {
symbol: 'url(/../Content/Img/ao-calendar.png)',
}
},
{
x: 0.40,
y: Date.UTC(2016,4,10),
marker: {
symbol: 'url(/../Content/Img/ao-graph.png)',
}
},
{
x: 0.40,
y: Date.UTC(2016,6,15),
marker: {
symbol: 'url(/../Content/Img/ao-runningman.png)',
}
},
{
x: 0.40,
y: Date.UTC(2016, 8, 5),
marker: {
symbol: 'url(/../Content/Img/ao-a.png)',
}
},
{
x: 0.40,
y: Date.UTC(2016, 10, 15),
marker: {
symbol: 'url(/../Content/Img/ao-green-arrow.png)',
}
}
]
}
]
});
});
如图所示,如果我们在图表上单击/悬停,则应显示灰色背景。
请帮忙。提前致谢!!
【问题讨论】:
-
您有带有自定义标签的代码的实时示例吗?喜欢 jsFiddle?
-
你可以参考这个jsfiddle链接:jsfiddle.net/0jpovpzr
-
您可以制作自定义十字准线,制作更长的网格线并将标签的类别更改为选中(例如使用 jQuery)。在这里你可以看到一个例子:jsfiddle.net/0jpovpzr/2
-
@GrzegorzBlachliński 真是太棒了,非常感谢!我忘了添加一些悬停/单击事件反之亦然的东西。如果我们也点击标签,图表应该被选中。这可能吗?
-
是的,这是可能的,看这个例子:jsfiddle.net/0jpovpzr/4
标签: javascript jquery css charts highcharts