在Stacked Bar charts + Highcharts中选定系列的边框

时间:2015-02-24 09:51:57

标签: jquery css highcharts

我使用高级图表来渲染堆积条形图。

当用户点击特定系列时,如何在堆积条形图上获取边框?我尝试了标记选项但是只选择了一个系列,但我希望选择完整的系列。

目前我的情况如下: -

但是,我想这样: -

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以使用渲染器在后台添加此类rect:http://jsfiddle.net/3Utat/25/

    mouseOver: function () {
        var chart = this.series.chart,
            r = chart.renderer,
            shape = this.shapeArgs, // shape args for the points rect element
            xAxis = this.series.xAxis,
            yAxis = this.series.yAxis,
            y = yAxis.toPixels(this.total), // top left y-position of the rect
            x = this.plotX + chart.plotLeft - shape.width / 2, // point position + left offset + half width
            height = yAxis.toPixels(yAxis.min) - y; // bottom - top

        if (chart.hoverStack) {
            chart.hoverStack.destroy();
        }

        chart.hoverStack = r.rect(x, y, shape.width, height).attr({
                'stroke-width': 6, //border width
                'stroke': 'black', //border color
                'fill': 'transparent' //transparent fill color
        }).add();

    },
    mouseOut: function () {
        if (this.series.chart.hoverStack) {
            this.series.chart.hoverStack.destroy();
            this.series.chart.hoverStack = false;
        }
    }

示例是使用mouseOvermouseOut事件,但在您的情况下,您可以改为使用click事件。

答案 1 :(得分:0)

按照Pawel的建议,选择了正确的边框小提琴 堆积条形图是: -

http://jsfiddle.net/3Utat/26/

click: function () {
                        var chart = this.series.chart,
                            r = chart.renderer,
                            shape = this.shapeArgs,
                            xAxis = this.series.xAxis,
                            yAxis = this.series.yAxis,
                            y = yAxis.toPixels(this.total),
                            x = this.plotX - shape.width / 2,
                            height = Math.abs(yAxis.toPixels(yAxis.min) - y);

                        if (chart.hoverStack) {
                            chart.hoverStack.destroy();
                        }

                        chart.hoverStack = r.rect(x, chart.plotWidth+chart.plotLeft-y, shape.width, height).attr({
                            'stroke-width': 6,
                                'stroke': 'black',
                            fill: 'transparent',
                            transform: 'translate(' + (chart.plotWidth+chart.plotLeft) + ' ' +  (chart.plotHeight+chart.plotTop) + ' ) rotate(90) scale(-1,1)'
                        }).add();

                    }