gpt4 book ai didi

highcharts - 如何在放大 Highcharts 时启用 y 轴平移?

转载 作者:行者123 更新时间:2023-12-03 16:28:20 26 4
gpt4 key购买 nike

我想在放大图表时在 Y 轴上移动
现在我可以在缩放时在 X 轴上移动

波纹管是平移的代码

chart: {
renderTo: 'container1',
type: 'column',
zoomType: 'xy',
panning: true,
panKey: 'shift',}

任何帮助,将不胜感激

最佳答案

可能的解决方案:

  • 您可以在 Highstock 中设置垂直滚动条。
        yAxis: {
    scrollbar: {
    enabled: true
    }
    },

  • 文章: http://www.highcharts.com/news/224-scrollbars-for-any-axis

    演示: http://jsfiddle.net/gh/get/jquery/1.7.2/highcharts/highcharts/tree/master/samples/stock/yaxis/scrollbar/
  • 使用基于 the plugin 的包装器代码(包括在下面)由 建议芭芭拉 允许缩放 (xy) 和平移 (xy)。

  • 包装器代码:
    (function (H) {
    H.wrap(H.Chart.prototype, 'pan', function (proceed) {
    var chart = this,
    hoverPoints = chart.hoverPoints,
    doRedraw,
    e = arguments[1],
    each = H.each;

    // remove active points for shared tooltip
    if (hoverPoints) {
    each(hoverPoints, function (point) {
    point.setState();
    });
    }

    var mousePosX = e.chartX,
    mousePosY = e.chartY,
    xAxis = chart.xAxis[0],
    yAxis = chart.yAxis[0],
    startPosX = chart.mouseDownX,
    startPosY = chart.mouseDownY,
    halfPointRangeX = (xAxis.pointRange || 0) / 2,
    halfPointRangeY = (yAxis.pointRange || 0) / 2,
    extremesX = xAxis.getExtremes(),
    newMinX = xAxis.toValue(startPosX - mousePosX, true) + halfPointRangeX,
    newMaxX = xAxis.toValue(startPosX + chart.plotWidth - mousePosX, true) - halfPointRangeX,
    extremesY = yAxis.startingExtremes,
    newMaxY = yAxis.toValue(startPosY - mousePosY, true) + halfPointRangeY,
    newMinY = yAxis.toValue(startPosY + chart.plotHeight - mousePosY, true) - halfPointRangeY;

    if (xAxis.series.length && newMinX > Math.min(extremesX.dataMin, extremesX.min) && newMaxX < Math.max(extremesX.dataMax, extremesX.max) && newMinY > Math.min(extremesY.dataMin, extremesY.min) && newMaxY < Math.max(extremesY.dataMax, extremesY.max)) {
    xAxis.setExtremes(newMinX, newMaxX, false, false, {
    trigger: 'pan'
    });
    yAxis.setExtremes(newMinY, newMaxY, false, false, {
    trigger: 'pan'
    });
    doRedraw = true;
    }

    chart.mouseDownX = mousePosX;
    chart.mouseDownY = mousePosY;// set new reference for next run

    if (doRedraw) {
    chart.redraw(false);
    }
    });

    }(Highcharts));

    应在图表的回调或图表加载事件中设置起始极端值,例如:
        }, function(chart){
    chart.yAxis[0].startingExtremes = chart.yAxis[1].getExtremes();
    });

    演示: http://jsfiddle.net/Lxjqed02/3/

    关于highcharts - 如何在放大 Highcharts 时启用 y 轴平移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39413390/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com