有没有一种方法可以更改使用Highcharts拖动的步长。例如,当我有大数值(成千上万个)的数据时,拖动值并获得像4327这样的随机数是非常不干净的。我想做的就是将拖动值四舍五入到某个点基于y-scale的最大值,但我一直无法弄清楚如何做到这一点。因此,在这种情况下,拖动操作将从4300变为4400,而不是在它们之间获得随机数。这是一个JS小提琴,它演示了拖动时得到的不必要的数字:

jsFiddle

var planChart;

$(function () {
planChart = {
    chart: {

        animation: false
    },
    title: {
        text: ''
    },
    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
        crosshair: true,
    },
    yAxis: [{ // Primary yAxis
        labels: {
            format: '{value}',
            style: {
                color: '#20709e'
            }
        },
        title: {
            text: 'title',
            style: {
                color: '#20709e'
            }
        },
    }],

    plotOptions: {
        series: {
            point: {
                events: {

                    drag: function (e) {
                        // Returning false stops the drag and drops. Example:
                        /*
                        if (e.newY > 300) {
                            this.y = 300;
                            return false;
                        }
                        */


                    },
                    drop: function () {  }
                }
            },
            stickyTracking: false
        },
        column: {
            stacking: 'normal'
        },
        line: {
            cursor: 'ns-resize'
        }
    },

    tooltip: {
        shared: true
    },

    credits: {
        enabled: false
    },

    series: [{
        name: 'title',
        tooltip: {
            pointFormat: '<span style="color:{point.color}">\u25CF</span> <b> {point.y} </b><br/>'
        },
        data: [7042, 40494, 48204, 20383, 20938, 4803, 23903, 22, 23939, 13032, 1332, 93932],
        //draggableX: true,
        draggableY: true,
       dragMinY: 0,
        style: {
            color: '#20709e'
        }
    }]
}
$('.actualPlansPlot').highcharts(planChart);
 });

$(document).on('click', '#updateYScale', function(e) {
    var yValue = $('#newYValue')[0].value;
    planChart.yAxis[0].max = yValue;
    $('.actualPlansPlot').highcharts(planChart);
})


的HTML

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="https://rawgithub.com/highslide-software/draggable-points/master/draggable-points.js?1"></script>
<div class="actualPlansPlot" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
<input id="newYValue" type="number" />
<button id="updateYScale">Update Scale</button>


任何帮助将不胜感激!

最佳答案

这个怎么样?

tooltip: {
     shared: true,
     formatter: function () {
           return  this.x + '<br/><b>' + Math.ceil(this.y/100)*100 + '</b>';
     }
},


JSFiddle

关于javascript - 更改Highcharts Drag的步长?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33680949/

10-12 12:37