gpt4 book ai didi

javascript - IE11 预期标识符、字符串或数字错误

转载 作者:行者123 更新时间:2023-11-30 20:28:34 28 4
gpt4 key购买 nike

您好,我正在用变量填充 C3JS 值此脚本在 IE11 中有效,但在“colors: {”行上抛出错误“expected identifier, string or number error”

这是自定义颜色的 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
}
});

最佳答案

我是这样解决的

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
}
});

关于javascript - IE11 预期标识符、字符串或数字错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50609941/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com