将HI轴除以HIghchart中的可点击区域

问题描述 投票:1回答:1

我想在高图中的Area Graph中实现范围方面的xAxis。

区域应该是可点击的,应该过滤图表中的区域。

enter image description here

html highcharts
1个回答
2
投票

要在图表下方添加该行,您可以使用xAxis和适当的选项,但要添加自定义标签,您需要使用Highcharts.SVGRenderer

chart: {
    ...,
    events: {
        load: function() {
            var ticks = this.xAxis[0].ticks,
                customLabels = ['total: 13', 'Zone of Mediocrity', 'Stocks: 47', 'Good, not great', 'total: 13', 'Zone of "Greatness"'],
                counter = 0,
                xPos,
                tickPos;

            addEvents.call(this);

            Highcharts.objectEach(ticks, function(el) {
                if (tickPos) {
                    xPos = tickPos.x + (el.mark.getBBox().x - tickPos.x) / 2;
                    drawCustomLabel.call(
                        this,
                        customLabels[counter],
                        xPos,
                        tickPos.y + 10
                    );

                    drawCustomLabel.call(
                        this,
                        customLabels[counter + 1],
                        xPos,
                        tickPos.y + 30
                    );

                    counter += 2;
                }

                tickPos = el.mark.getBBox();
                el.mark.attr({
                    translateY: 7.5
                });
            }, this);
        }
    }
}

要将图表系列划分为几个元素,请使用zones。可以通过以下方式添加click事件:

function addEvents() {
    var series = this.series[0];

    series['zone-area-0'].element.addEventListener('click', function() {
        console.log('zone-area-0');
    });

    ...
}

现场演示:http://jsfiddle.net/BlackLabel/e619th3c/

API:

https://api.highcharts.com/class-reference/Highcharts.SVGRenderer

https://api.highcharts.com/highcharts/series.areaspline.zones

https://api.highcharts.com/highcharts/xAxis.tickPositions

© www.soinside.com 2019 - 2024. All rights reserved.