javascript - Highcharts - 更改系列中单个数据点的边框

标签 javascript highcharts

我正在使用 highcharts 来准备一些图表。我希望能够更改系列中特定点的边框颜色,但我无法让它工作(jsfiddle: http://jsfiddle.net/081e9sLy/4/ )

我将我的系列声明为

var subject1 = [20,22,24,28,24, { marker: {
                                    fillColor: 'green',
                                    lineWidth: 3,
                                    lineColor: "#f39c12"
                                 }, y:29}];

但第六个数据点上没有橙色边框。但是,如果我将 fillColor 更改为“红色”,则会更改数据点。

有什么建议吗?

编辑:经过进一步调查,当您将鼠标悬停在数据点上时,边界似乎是可见的(只是!)。但我需要它始终可见。

最佳答案

这似乎是一个错误。当在点的标记选项中定义 lineWidth 时,不会考虑 lineWidth。它在版本 4.2.7 http://jsfiddle.net/081e9sLy/7/ 中工作

如果您想在版本 5 中使用它,您可以尝试使用以下代码覆盖 Highcharts 方法。

Highcharts.seriesTypes.line.prototype.pointAttribs = function (point, state) {
var seriesMarkerOptions = this.options.marker,
                    seriesStateOptions,
                    pointOptions = point && point.options,
                    pointMarkerOptions = (pointOptions && pointOptions.marker) || {},
                    pointStateOptions,
                    strokeWidth = pointMarkerOptions.lineWidth || seriesMarkerOptions.lineWidth,
                    color = this.color,
                    pointColorOption = pointOptions && pointOptions.color,
                    pointColor = point && point.color,
                    zoneColor,
                    fill,
                    stroke,
                    zone;

                if (point && this.zones.length) {
                    zone = point.getZone();
                    if (zone && zone.color) {
                        zoneColor = zone.color;
                    }
                }

                color = pointColorOption || zoneColor || pointColor || color;
                fill = pointMarkerOptions.fillColor || seriesMarkerOptions.fillColor || color;
                stroke = pointMarkerOptions.lineColor || seriesMarkerOptions.lineColor || color;

                // Handle hover and select states
                if (state) {
                    seriesStateOptions = seriesMarkerOptions.states[state];
                    pointStateOptions = (pointMarkerOptions.states && pointMarkerOptions.states[state]) || {};
                    strokeWidth = pointStateOptions.lineWidth || seriesStateOptions.lineWidth || strokeWidth + seriesStateOptions.lineWidthPlus;
                    fill = pointStateOptions.fillColor || seriesStateOptions.fillColor || fill;
                    stroke = pointStateOptions.lineColor || seriesStateOptions.lineColor || stroke;
                }

                return {
                    'stroke': stroke,
                    'stroke-width': strokeWidth,
                    'fill': fill
                };

};

示例:http://jsfiddle.net/081e9sLy/9/

关于javascript - Highcharts - 更改系列中单个数据点的边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40282925/

相关文章:

javascript - 忽略/删除数组计数中的 null、未定义和空值 - Javascript

javascript - Node.js SELECT*FROM SQL 数据库中的表

php - Highcharts——从 mysql 获取类别

javascript - ES5/6/Next 在 JavaScript 中对数组进行分组或 block 迭代的方法

javascript - 使用 javascript 进行高效的实时 SVG 实体管理

javascript - 在 d3.js v6 中创建小倍数的最佳方法是什么?

Highcharts 3d条形图数据标签位置错误

javascript - 将两年中的一个月与 Highcharts 进行比较

javascript - HighCharts:是否可以删除 x 轴上的所有其他值?

javascript - 处理条形图中的点击事件