al404IT
al404IT

Reputation: 1418

IE11 Expected identifier, string or number error

Hi i'm populating C3JS values with variables this scripts works except in IE11 that throw an error "expected identifier, string or number error" on "colors: {" line

this is C3JS example for custom colors http://c3js.org/samples/data_color.html

in my case referred value is inside a variable

I found this solution that works except on 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
                                }
                            });

Upvotes: 1

Views: 1426

Answers (1)

al404IT
al404IT

Reputation: 1418

This is how I fixed

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

Upvotes: 1

Related Questions