在Highchart传说中,想要在启动时带上复选框 [英] In Highchart legend, Want to bring checkbox at start

查看:113
本文介绍了在Highchart传说中,想要在启动时带上复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在项目名称前面加上复选框,通常在项目名称后面。
请参阅下图以获取更多描述。

I want to bring Checkbox before item name which are normally after the item name. Refer below image for more description.

推荐答案

默认情况下不支持,但您可以使用简单的解决方法来查看: http://jsfiddle.net/Le4Vc/4/

By default it's not supported, but you can use simple workaround for this, see: http://jsfiddle.net/Le4Vc/4/

$('#container').highcharts({

    chart: {
        events: {
            load: function() {
                var chart = this;

                $.each(chart.legend.allItems, function(i, item){
                    var $check = $(item.checkbox),
                        left = parseFloat($check.css('left')),
                        label = item.legendItem,
                        static = 30;

                    $check.css({
                        left: (left - label.bBox.width - static) + 'px'  
                    });
                });

            }
        }
    },

    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },
    plotOptions: {
        series: {
            marker: {
                enabled: false
            },
            allowPointSelect: true,
            showCheckbox: true
        }
    },
    legend: {
        symbolPadding: 20,
        symbolWidth: 0
    },
    series: [{
        name: 's 1',
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    },{
        name: 'another name',
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4].sort(function(a,b) { return a - b; })
    }]

});

编辑:
另一个解决方案, positionCheckboxes 函数。例如:

Another solution, more universal is to wrap positionCheckboxes function. For example:

(function (H) {
    H.wrap(H.Legend.prototype, 'positionCheckboxes', function (p, scrollOffset) {
        var alignAttr = this.group.alignAttr,
            translateY,
            clipHeight = this.clipHeight || this.legendHeight;

        if (alignAttr) {
            translateY = alignAttr.translateY;
            H.each(this.allItems, function (item) {
                var checkbox = item.checkbox,
                    bBox = item.legendItem.bBox,
                    top;

                if (checkbox) {
                    top = (translateY + checkbox.y + (scrollOffset || 0) + 3);
                    H.css(checkbox, {
                        left: (alignAttr.translateX + item.checkboxOffset + checkbox.x - 60 - bBox.width) + 'px',
                        top: top + 'px',
                        display: top > translateY - 6 && top < translateY + clipHeight - 6 ? '' : 'none'
                    });
                }
            });
        }
    });
})(Highcharts);

演示: http://jsfiddle.net/Le4Vc/85/

这篇关于在Highchart传说中,想要在启动时带上复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆