【问题标题】:Highcharts - Hide the Reset zoom button alwaysHighcharts - 始终隐藏重置缩放按钮
【发布时间】:2017-07-02 11:10:52
【问题描述】:

如何始终在 highcharts 中隐藏重置缩放按钮。我有用于放大和缩小的自定义按钮。如何始终在高图中隐藏重置缩放按钮。我有用于放大和缩小的自定义按钮。如何始终在高图中隐藏重置缩放按钮。我有用于放大和缩小的自定义按钮。如何始终在高图中隐藏重置缩放按钮。我有用于放大和缩小的自定义按钮。 $(函数(){ /** * Highcharts 插件,用于在图表之外的单独容器中显示工具提示 *边界框,以便它可以利用页面中的所有可用空间。 */

(function(H) {
    H.wrap(H.Tooltip.prototype, 'getLabel', function(proceed) {

        var chart = this.chart,
            options = this.options,
            chartRenderer = chart.renderer,
            box;

        if (!this.label) {

            this.renderer = new H.Renderer(document.body, 400, 500);
            box = this.renderer.boxWrapper;
            box.css({
                position: 'absolute',
                top: '-9999px'
            });
            chart.renderer = this.renderer;
            proceed.call(this, chart, options);
            chart.renderer = chartRenderer;

            this.label.attr({
                x: 0,
                y: 0
            });
            this.label.xSetter = function(value) {
                box.element.style.left = value + 'px';
            };
            this.label.ySetter = function(value) {
                box.element.style.top = value + 'px';
            };
        }
        return this.label;
    });

    H.wrap(H.Tooltip.prototype, 'getPosition', function(proceed, boxWidth, boxHeight, point) {
        var chart = this.chart,
            chartWidth = chart.chartWidth,
            chartHeight = chart.chartHeight,
            pos;
        point.plotX += this.chart.pointer.chartPosition.left;
        point.plotY += this.chart.pointer.chartPosition.top;

        // Temporary set the chart size to the full document, so that the tooltip positioner picks it up
        chart.chartWidth = $(document).width();
        chart.chartHeight = $(document).height();

        // Compute the tooltip position
        pos = proceed.call(this, boxWidth, boxHeight, point);

        // Reset chart size
        chart.chartWidth = chartWidth;
        chart.chartHeight = chartHeight;

        return pos;
    });

    /**
     * Find the new position and perform the move. This override is identical
     * to the core function, except the anchorX and anchorY arguments to move().
     */
    H.Tooltip.prototype.updatePosition = function(point) {
        var chart = this.chart,
            label = this.label,
            pos = (this.options.positioner || this.getPosition).call(
                this,
                label.width,
                label.height,
                point
            );

        // do the move
        this.move(
            Math.round(pos.x),
            Math.round(pos.y || 0), // can be undefined (#3977)
            point.plotX + chart.plotLeft - pos.x,
            point.plotY + chart.plotTop - pos.y
        );
    };

}(Highcharts));


    let data = [{
        values: [
            1.0,
            0.0
        ],
        name: "#1"
    }, {
        values: [
            0.0, -1.0
        ],
        name: "#2"
    }, {
        values: [
            0.0,
            0.0
        ],
        name: "#3"
    }, {
        values: [-1.0,
            0.0
        ],
        name: "#4"
    }, {
        values: [
            0.0,
            0.0
        ],
        name: "#5"
    }];
    let chart = Highcharts.chart('container', {
        chart: {
            type: 'line',
            height: 45,
            style: {
                overflow: 'visible'
            }
        },
        xAxis: {
            minPadding: 0.000,
            maxPadding: 0.000,
            startOnTick: false,
            endOnTick: false,
            tickWidth: 0,
            gridLineWidth: 0,
            lineWidth: 0,
            labels: {
                enabled: false
            },
            title: {
                text: null
            }
        },
        yAxis: {
            minPadding: 0.001,
            maxPadding: 0.001,
            gridLineWidth: 0,
            lineWidth: 0,
            labels: {
                enabled: false
            },
            title: {
                text: null
            }
        },
        lang: {
            noData: 'No data'
        },
        credits: {
            enabled: false
        },
        legend: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        title: {
            text: ''
        },
        tooltip: {
            shared: true
        },
        plotOptions: {
            series: {
                marker: {
                    enabled: false
                }
            }
        },
        series: [{
            data: []
        }]

    });
    data.forEach((seriesData) => {
        chart.addSeries({
            name: seriesData.name,
            data: seriesData.values
        });
    });
}); 

【问题讨论】:

    标签: highcharts


    【解决方案1】:

    您可以扩展Chart.showResetZoom 以通过根本不执行函数来不绘制按钮。例如(JSFiddle):

    (function (H) {
        H.wrap(H.Chart.prototype, 'showResetZoom', function (proceed) {
        });
    }(Highcharts));
    

    【讨论】:

    • 非常感谢 Halvor!这正是我想要的!
    • 我还有一个问题。如果可能的话,请帮忙。我可以在单击自定义缩小按钮时调用 zoomOut()。但是,如果我在单击自定义按钮中的缩放时调用 zoom(),则它不起作用。我确实看到了在 highcharts 的源代码中定义的 zoom() 。我对这个功能的理解是错误的吗?请指导
    • zoom 函数接受一个鼠标事件并使用它的属性来确定缩放位置。您必须以某种方式指定缩放位置。有关示例,请参阅 this small example,但要了解更多详细信息,我会提出一个单独的问题。
    • 感谢您提供详细信息。我发布了一个新问题。 stackoverflow.com/questions/44871917/…
    【解决方案2】:

    您可以将按钮的 CSS display 属性设置为 none

    chart1 = new Highcharts.Chart({
        chart: {
            type: 'line',
            zoomType: 'x',
            renderTo: 'chart',
            resetZoomButton: {
                theme: { style: { display: 'none'} }
            }
        },
        ...
    

    或者你可以强制按钮显示然后销毁它。

    chart1 = new Highcharts.Chart({ ... });
    
    chart1.showResetZoom();
    chart1.resetZoomButton.destroy();
    

    【讨论】:

      猜你喜欢
      • 2013-02-08
      • 1970-01-01
      • 2021-06-06
      • 2017-12-05
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多