IE11预期的标识符,字符串或数字错误

时间:2018-05-30 16:56:31

标签: javascript c3.js

您好我用变量填充C3JS值 这个脚本的工作原理除了在IE11中引发错误"期望的标识符,字符串或数字错误" on" colors:{"线

这是自定义颜色的C3JS示例 http://c3js.org/samples/data_color.html

在我的案例中,引用值在变量

我发现这个解决方案除了在IE11上有效之外

var c1L = "Company 1";
var c2L = "Company 2";
var c3L = "Company 3";

var c1F = 1100;
var c2F = 550;
var c3F = 300;

var c1C = "#001122";
var c2C = "#001133";
var c3C = "#001144";

var chartPortafolio01 = c3.generate({
                                bindto: d3.select('#chart-portafolio-01'),
                                data: {
                                    columns: [
                                        [c1L, c1F],
                                        [c2L, c2F],
                                        [c3L, c3F]
                                    ],
                                    type : 'donut',
                                    colors: {
                                        [c1L]: c1C,
                                        [c2L]: c2C,
                                        [c3L]: c3C
                                    }
                                },
                                donut: {
                                    title: "€ " + formattaNumHtml(clientiTotale)
                                },
                                legend: {
                                    show: false
                                }
                            });

1 个答案:

答案 0 :(得分:1)

这是我修复的方式

var c1L = "Company 1";
var c2L = "Company 2";
var c3L = "Company 3";

var c1F = 1100;
var c2F = 550;
var c3F = 300;

var c1C = "#001122";
var c2C = "#001133";
var c3C = "#001144";

// fix IE11
var colorsObj = {};

for (var i = 1; i <= 3; i++) {                      
    colorsObj[eval("c" + i + "L")] = eval("c" + i + "C");                       
}

var chartPortafolio01 = c3.generate({
                bindto: d3.select('#chart-portafolio-01'),
                data: {
                    columns: [
                        [c1L, c1F],
                        [c2L, c2F],
                        [c3L, c3F]
                    ],
                    type : 'donut',
                    colors: colorsObj
                },
                donut: {
                    title: "€ " + formattaNumHtml(clientiTotale)
                },
                legend: {
                    show: false
                }
            });