javascript - 在 Highchart 中的不同位置显示图例和 colorAxis

标签 javascript highcharts heatmap

我想显示legend对于顶部的线系列和 colorAxis用于图表右侧的热图。有一个全局选项来定位图例,但每个系列没有单独的选项。

Highcharts版本:v4.3.1

最佳答案

该功能尚未在 Highcharts 核心中实现,但应该很快就会推出:https://github.com/highcharts/highcharts/issues/11309

现在,您可以通过以下方式将 colorAxis 从图例移动到图表上的其他位置:

(function(H) {
    H.wrap(H.ColorAxis.prototype, 'drawLegendSymbol', function(proceed) {
        proceed.apply(this, Array.prototype.slice.call(arguments, 1));

        this.legendItemWidth = 0;
        this.legendItemHeight = 0;
    });
}(Highcharts));

Highcharts.chart('container', {
    chart: {
        marginRight: 80,
        events: {
            load: function() {
                var chart = this,
                    colorAxis = chart.colorAxis[0].axisParent.element,
                    mainSVG = chart.container.children[0],
                    xPos = chart.plotLeft + chart.plotWidth + 10,
                    yPos = chart.plotTop;

                mainSVG.appendChild(colorAxis);

                colorAxis.setAttribute(
                    'transform', 'translate(' + xPos + ', ' + yPos + ')'
                )
            }
        }
    },
    series: [{
        ...,
        showInLegend: true
    }, {
        ...,
        showInLegend: true
    }],
    colorAxis: {
        layout: 'vertical'
    }
});
<小时/>

现场演示: http://jsfiddle.net/BlackLabel/0c9fkvwp/

API引用: https://api.highcharts.com/highcharts/chart.events

文档: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts

关于javascript - 在 Highchart 中的不同位置显示图例和 colorAxis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59323741/

相关文章:

javascript - DOM XSS 和 Javascript 转义

javascript - 我将如何将变量从 .on() 事件传递到回调函数?

javascript - 带渐变的 Highcharts 饼图 donut

r - R 中的不连续热图

javascript - 正则表达式尝试匹配符号之前和之后的字符

javascript - 将从网站加载的 Javascript 文件的执行替换为我自己的

highcharts - 在 highcharts 中实现滚动条

jquery - Highchart - 更改 y 轴标题的位置

javascript - 使用 d3 绘制热图

r - 从 R 中的点绘制热图