Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ie6下图表legend显示错误 #114

Open
KohPoll opened this issue Jun 19, 2014 · 1 comment
Open

ie6下图表legend显示错误 #114

KohPoll opened this issue Jun 19, 2014 · 1 comment

Comments

@KohPoll
Copy link

KohPoll commented Jun 19, 2014

ie6浏览器下,图表的legend只显示了一个。
image

@KohPoll
Copy link
Author

KohPoll commented Jun 19, 2014

暂时可以这样来fix,配置legend不显示,手动加进去。参考:http://kcharts.taobao.net/demo_page.php?id=58

var step = (data.xAxis.text.length <= 10) ? 1 : Math.floor(data.xAxis.text.length / 10);
var yText = (function (series) {
    var min = 0, max = 0, inc, rt = [], base;
    for (var i = 0, len = series.length; i < len; i += 1) {
        var cur = series[i];
        var cMin = Math.min.apply(null, cur.data);
        var cMax = Math.max.apply(null, cur.data);
        if (cMin < min) {
            min = cMin;
        }
        if (cMax > max) {
            max = cMax;
        }
    }
    min = Math.floor(min); max = Math.ceil(max);
    base = Math.pow(10, ((max + '').length - 1));
    max += base;

    for (var n = min; n <= max; n += base) {
        rt.push(n);
    }
    return rt;
})(data.series);

var fixLegend = (UA.ie == 6);

var cfg = {
    renderTo: el,
    themeCls: 'ks-chart-analytiks',
    points: {
        attr: {
            type: 'circle'
        }
    },
    comparable: true,
    legend: {
        isShow: !fixLegend,
        y: -10
    },
    xLabels: {
        template: function (index, text) {
            if (index % step == 0) {
                return text;
            } else {
                return '';
            }
        }
    },
    yAxis: {
        text: yText
    },
    tip: {
        offset: {
            x: 10,
            y: 10
        },
        template: function(e) {
            var html = '', t = '<span style="color:{color}">{text}{y}</span><br>';
            for (var i in e.datas) {
                html += S.substitute(t, {
                    color: e.datas[i]['color'],
                    text: e.datas[i]['text'],
                    y: e.datas[i]['y']
                });
            }
            return html;
        }
    }
};

var chart = new LineChart(S.merge(cfg, data));

if (fixLegend) {
    var id = 'fixed-legend_' + S.guid();
    var html = '<div id="' + id + '" class="fixed-legend"><div class="inner">';
    for (var i = 0, len = chart._cfg.series.length; i < len; i+=1) {
        var name = chart._cfg.series[i]['text'];
        html += '<span style="color:' +
            chart.color.getColor(i)['DEFAULT'] + ';">'+ name +
            '</span>';
    }
    html += '</div></div>';

    S.one(html).appendTo(el);
    S.one('#' + id).on('click', function (ev) {
        if (ev.target.tagName.toLowerCase() == 'span') {
            var curIndex = S.indexOf(ev.target, $('span', $(ev.currentTarget)));
            var target = S.one(ev.target);

            if (target.hasClass('disable')) {
                chart.showLine(curIndex);
                target.removeClass('disable');
            } else {
                chart.hideLine(curIndex);
                target.addClass('disable');
            }
        }
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant