简体   繁体   English

Chart.js:更稀疏的可点击数据点

[英]Chart.js : sparser clickable data points

I've got a chart.js line chart, with 128 datapoints.我有一个 chart.js 折线图,有 128 个数据点。

Currently, it uses the solution here for drag and drop verticals.目前,它使用此处的解决方案进行垂直拖放。

But it's a hassle.但这很麻烦。 I'd like to limit the clickable / editable points to 30 or so.我想将可点击/可编辑点限制在 30 个左右。

(Then ideally it would do some smart interpolation of the surrounding values.) (理想情况下,它会对周围的值进行一些智能插值。)

Any ideas how to achieve this?任何想法如何实现这一目标?

    function move_handler(event)
{
    // locate grabbed point in chart data
    if (activePoint != null) {
        var data = activePoint._chart.data;
        var datasetIndex = activePoint._datasetIndex;

        // read mouse position
        const helpers = Chart.helpers;
        var position = helpers.getRelativePosition(event, myChart);

        // convert mouse position to chart y axis value
        var chartArea = window.myChart.chartArea;
        var yAxis = window.myChart.scales["y-axis-0"];
        var yValue = map(position.y, chartArea.bottom, chartArea.top, yAxis.min, yAxis.max);

        // update y value of active data point
        data.datasets[datasetIndex].data[activePoint._index] = yValue;


//        try {
//            for (let i = -5;i < 5;i++){
//                data.datasets[datasetIndex].data[activePoint._index + i] = yValue;
//            }
//        }
//        catch (err) {}

        window.myChart.update();
    };
};

I found Smooth.js which did the trick我找到了成功的Smooth.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM