Highcharts 图形默认系列填充颜色覆盖状态填充颜色(包括 jsfiddle)
Highcharts graph default series fillColor overrides the state fillColors (jsfiddle included)
我希望能够设置箱线系列的填充颜色,然后在某些状态下覆盖该颜色(悬停并选择)。
问题是,每当我设置默认的 fillColor 时,悬停和选择状态都不再起作用,并且只使用默认的 fillColor。
如果没有设置默认的填充颜色,那么状态 fillColors 也不起作用(我猜是因为它们依赖于已经设置为工作的 fillColor 属性)。
但是,如果我将默认 fillColor 设置为无效设置,例如"#fsdfrw4jh432",那么它"sorta"就可以工作了。也就是说,各州现在工作。
看看这个jsfiddle,明白我的意思:http://jsfiddle.net/wiseguy205/b3CuF/1/
正如你从那个jsfiddle中看到的,悬停和选择状态是有效的,尽管填充颜色开始时是黑色的,因为它是一个无效的颜色代码。如果将颜色代码更改为正确的颜色,则状态将不再有效。
知道我做错了什么吗?
顺便说一句,这是jsfiddle代码:
$(function () {
$('#container').highcharts({
chart: {
type: 'boxplot'
},
title: {
text: 'Highcharts Box Plot Example'
},
legend: {
enabled: false
},
plotOptions: {
series: {
allowPointSelect: true,
states:{
hover: {
enabled: true,
lineWidth: 5,
fillColor: '#0F0'
},
select: {
fillColor: '#F00',
enabled: 'true'
}
},
fillColor: '#00dddddF',
}
},
xAxis: {
categories: ['1', '2', '3', '4', '5'],
title: {
text: 'Experiment No.'
}
},
yAxis: {
title: {
text: 'Observations'
},
plotLines: [{
value: 932,
color: 'red',
width: 1,
label: {
text: 'Theoretical mean: 932',
align: 'center',
style: {
color: 'gray'
}
}
}]
},
series: [{
name: 'Observations',
data: [
[760, 801, 848, 895, 965],
[733, 853, 939, 980, 1080],
[714, 762, 817, 870, 918],
[724, 802, 806, 871, 950],
[834, 836, 864, 882, 910]
],
tooltip: {
headerFormat: '<em>Experiment No {point.key}</em><br/>'
}
}, {
name: 'Outlier',
color: Highcharts.getOptions().colors[0],
type: 'scatter',
data: [ // x, y positions where 0 is the first category
[0, 644],
[4, 718],
[4, 951],
[4, 969]
],
marker: {
fillColor: 'white',
lineWidth: 1,
lineColor: Highcharts.getOptions().colors[0]
},
tooltip: {
pointFormat: 'Observation: {point.y}'
}
}]
});
// the button action
$('#button').click(function() {
var selectedPoints = $('#container').highcharts().getSelectedPoints();
alert ('You selected '+ selectedPoints.length +' points');
});
});
好的,
我为这个错误开发了一个解决方法,人们可以使用它,直到 highcharts 团队实际修补它。
这是jsFiddle。
http://jsfiddle.net/b3CuF/16/
以下是后代的实际代码:
$(function () {
var savedFill ='#2c8';
$('#container').highcharts({
chart: {
type: 'boxplot',
events: {
load: function(event) {
var todayT = $('#container').highcharts();
//console.log(this);
//console.log(this.series[0].data);
//this.series.data[0].pointAttr[''].fill = savedFill;
//this.series.data[0].select();
for (var i=0;i<this.series[0].data.length;i++){
//this.series.data[i].select();
console.log(this.series[0].data[i]);
this.series[0].data[i].select();
console.log(i);
if (i == this.series[0].data.length-1){
this.series[0].data[0].select(false);
}
}
//this.series[0].data[0].unselect();
//this.series[0].data[4].select(false);
}
}
},
title: {
text: 'Highcharts Box Plot Example'
},
legend: {
enabled: false
},
plotOptions: {
series: {
allowPointSelect: true,
states:{
hover: {
enabled: true,
lineWidth: 5,
fillColor: '#0F0'
},
select: {
fillColor: savedFill,
enabled: 'true'
}
},
fillColor: 'notNull',
point: {
events: {
mouseOver: function(e) {
//console.log($('#container').highcharts());
var hChartObj = $('#container').highcharts();
//hChartObj.series[0].update({
// color: '#FF0000'
//});
//this.update({
// color: '#FF0000'
//});
//console.log(this.series.data[0]);
console.log(Object.keys(this.series.data[0].pointAttr));
//console.log(this);
this.series.data[0].pointAttr.hover.fill = '#60d0ff';
this.series.data[0].pointAttr.select.fill = '#ff6081';
this.series.data[0].pointAttr[''].fill = savedFill;
//this.series.data[0].pointAttr.%20.fill = '#ff6081';
//this.series.data[0].pointAttr.fill = {fill:'#60d0ff',stroke:'#2f7ed8',stroke-width:1};
//this.series.data[0].graphic.fill = '#000000';
//this.series.data[0].series.color = '#000000';
//this.series.data[0].box.fill = '#60d0ff';
//console.log('updated');
//console.log(this.series.data[0].pointAttr);
//this.update({
// name: 'yup'
//});
//this.series.data[0].graphic.fill('destroy');
//this.series.data[0].graphic.fill = '#000000';
//hChartObj.series[0].remove(true);
},
mouseOut: function() {
console.log('out');
//this.series.data[0].pointAttr.hover.fill = savedFill;
//console.log(this.series.data[0].pointAttr);
},
select: function() {
this.series.data[0].pointAttr[''].fill = savedFill;
},
unselect: function() {
this.series.data[0].pointAttr[''].fill = savedFill;
}
}
}
}
},
xAxis: {
categories: ['1', '2', '3', '4', '5'],
title: {
text: 'Experiment No.'
}
},
yAxis: {
title: {
text: 'Observations'
},
plotLines: [{
value: 932,
color: 'red',
width: 1,
label: {
text: 'Theoretical mean: 932',
align: 'center',
style: {
color: 'gray'
}
}
}]
},
series: [{
name: 'Observations',
data: [
[760, 801, 848, 895, 965],
[733, 853, 939, 980, 1080],
[714, 762, 817, 870, 918],
[724, 802, 806, 871, 950],
[834, 836, 864, 882, 910]
],
tooltip: {
headerFormat: '<em>Experiment No {point.key}</em><br/>'
}
}, {
name: 'Outlier',
color: Highcharts.getOptions().colors[0],
type: 'scatter',
data: [ // x, y positions where 0 is the first category
[0, 644],
[4, 718],
[4, 951],
[4, 969]
],
marker: {
fillColor: 'white',
lineWidth: 1,
lineColor: Highcharts.getOptions().colors[0]
},
tooltip: {
pointFormat: 'Observation: {point.y}'
}
}]
});
// the button action
$('#button').click(function() {
var selectedPoints = $('#container').highcharts().getSelectedPoints();
alert ('You selected '+ selectedPoints.length +' points');
});
});
我需要更改框的轮廓。 不完全一样,但由于我找不到任何东西,我将在这里发布一个示例小提琴。
重点是:
var colorBox = function(point, selected) {
var series = point.series,
seriesOptions = series.options,
seriesStates = seriesOptions.states,
stem = point.stem,
box = point.box,
whiskers = point.whiskers,
medianShape = point.medianShape;
var selectedStroke = seriesStates.select
? seriesStates.select.color
: null;
var stroke = selected
? selectedStroke
: point.color || series.color;
stem.attr({ 'stroke': stroke });
box.attr({ 'stroke': stroke });
whiskers.attr({ 'stroke': stroke });
medianShape.attr({ 'stroke': stroke });
};
相关文章:
- 椭圆字幕选择,然后在Photoshop中使用Javascript填充颜色
- 如何访问svg内部id并让CSS更改该id的填充颜色
- 如何使用fabricjs在图像中插入填充颜色
- 边距和输入元素边框之间的填充颜色
- OL3:如何获取矢量图层的现有样式属性(例如填充颜色、描边颜色等)
- 无法重置 SVG 路径的填充颜色
- 当 y 轴反转时是否可以保持填充颜色
- 我可以用LeafLet更改GeoJSON LineString的填充颜色吗?
- 如何在单击 SVG 用作背景图像时更改其填充颜色
- HTML 5 画布填充颜色
- 美国地图拉菲尔插件自动更新和动态填充颜色
- 更改高图表散点图中的制造商填充颜色
- 更改 svg 填充颜色,然后绘制到画布
- 我可以根据图表中的给定阈值设置不同的填充颜色吗.js
- 无法在谷歌地图符号 (svg) 标记中填充颜色
- Highcharts 图形默认系列填充颜色覆盖状态填充颜色(包括 jsfiddle)
- 如何获取HTML5画布元素的填充颜色
- 更改d3.js节点的填充颜色
- Highcharts-悬停时x坐标之间的不同填充颜色
- OpenLayers 3根据要素参数值更改点填充颜色