简体   繁体   English

HighCharts:即时重新排序yAxis类别不会正确绘制

[英]HighCharts: reordering yAxis categories on the fly won't draw properly

I have a function that will allow me to add a series dynamically to my highchart. 我有一个函数,可以让我向highchart动态添加一个序列。 (I'm adding series's with their names as integer values and have them sorted in ascending order). (我正在添加系列,其名称为整数值,并按升序排序)。

$('#addSeries').on('click', function() {
    //first check if value is already a series
    var seriesid = document.getElementById('txtValue').value;
    getSeriesIDIndex(seriesid, function(idindex) {
        //if it doesnt exist, add it to chart
        if (idindex == -1) {
            categories.push(parseInt(seriesid));
            categories = categories.sort(sortNumber);
            chart.yAxis[0].setCategories(categories, false);
            getCategoryIndex(parseInt(seriesid), function(cindex) {
                chart.addSeries({name: seriesid,  data: [{x: currentDate.getTime(), y: cindex}]}, false);

                for (i = 0; i < chart.series.length; i++) {
                    (function(i) {
                        getCategoryIndex(chart.series[i].name, function(cindex) {
                            for (y = 0; y < chart.series[i].data.length; y++) {
                                chart.series[i].data[y].y = cindex;
                                chart.redraw();
                            }
                        });
                    })(i);
                }

                chart.redraw();
            });
        }
    });

First add a series "123", then "44" and it will not display properly... but then add another series "555" and it gets redrawn properly. 首先添加一个系列“ 123”,然后添加“ 44”,它将无法正确显示...但是随后添加另一个系列“ 555”,它将正确重绘。 The category indeces for these would be 0 for 44, 1 for 123, and 2 for 555 (because I want to keep the series categories in ascending order). 这些的类别索引分别为0(代表44),1(代表123)和2(代表555)(因为我想使系列类别保持升序)。 So it seems that when adding a series category of lesser value than the other categories, it won't redraw correctly 因此,当添加比其他类别小的价值的类别类别时,它将无法正确重绘

I've also created a jsfiddle: http://jsfiddle.net/5L59r1qt/17/ 我还创建了一个jsfiddle: http : //jsfiddle.net/5L59r1qt/17/

Please take a look at http://jsfiddle.net/qner9hwc/1/ 请看一下http://jsfiddle.net/qner9hwc/1/

             getCategoryIndex(parseInt(seriesid), function (cindex) {
                chart.addSeries({
                    name: seriesid,
                    data: [{
                        x: currentDate.getTime(),
                        y: cindex
                    }]
                }, false);
                for (i = 0; i < chart.series.length; i++) {
                    var cur_series = chart.series[i];
                    var cur_cindex;
                    getCategoryIndex(chart.series[i].name, function (cindex) {
                        cur_cindex = cindex;
                    });
                    for (var z = 0; z < cur_series.data.length; z++) {
                        if (cur_series.data[z].y >= cindex && cur_series.name !== seriesid) {
                            console.log('change!' + cur_series.data[z].y);
                            cur_series.data[z].y = cur_cindex;
                        }
                    }
                }
                console.log(chart.yAxis[0].categories);
                chart.redraw();
            });

The y values now get changed accordingly; 现在,y值会相应更改;

However the yaxis is a little bit too high right now. 但是yaxis现在太高了。 Maybe the others can figure out why that is the case. 也许其他人可以弄清楚为什么会这样。 (look at the tooltip on state hover, the values are correct now) (查看状态悬停工具提示,现在值正确)

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

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