未捕获的TypeError:无法读取图表js中未定义的属性'fontSize'

时间:2019-07-25 02:45:47

标签: javascript

此代码用于在DataTable中显示图表。 一切都很好。 但是突然之间 我什么都没改变。 但是代码无法运行。

我已经尝试了很多次,一切都失败了。

  

未捕获的TypeError:无法读取未定义的属性'fontSize'

 sub_table.DataTable({
        dom: 'Bfrtip',
        responsive: true,
        "ajax": {
            "url": base_url+"services/key_track_result_detail",
            "type": "POST",
            "data": {asin_id: d.id}
        },
        "columns": [
            { "data": 'num' },
            { "data": 'keyword' },
            { "data": 'exact' },
            { "data": 'broad' },
            { "data": 'competing' },
            {
                "data": 'trend'
            },
            { "data": 'rank' },
            { "data": 'key_id' }
        ],
        columnDefs: [
            {
                targets: -3,
                title: 'Trend',
                orderable: false,
                render: function(data, type, full, meta) {
                    return `
                            <canvas height="50" class="chart-trend" chart-data='`+JSON.stringify(data)+`' width="283"></canvas>
                        `;
                },
            },
        ],
        "order": [[0, 'asc']],
        "fnInitComplete": function (oSettings, json) {

            $(".chart-trend").each( function () {
                var str_json = $(this).attr('chart-data');
                var response = JSON.parse(str_json);

                var data = [];
                var dataset = [];
                var labels = [];
                $.each(response.labels, function (i, val) {
                    labels.push(val);
                });
                data['labels'] = labels;

                $.each(response.datasets, function (i, val) {

                    var product = [];
                    var datas = [];
                    $.each(val.data, function (j, data) {
                        datas.push(data);
                    });
                    product['data'] = datas;
                    product['label'] = val.label;
                    product['borderColor'] = val.borderColor;
                    product['fill'] = val.fill;
                    product['lineTension'] = 0;

                    dataset.push(product) ;
                });
                data['datasets'] = dataset;

                var setting = {
                    responsive: true,
                    legends: {
                        display: false
                    },
                    scales: {
                        xAxes: [{
                            display: false,
                            scaleLabel: {
                                display: true,
                                labelString: 'Month'
                            }
                        }],
                        yAxes: [{
                            display: false,
                            scaleLabel: {
                                display: true,
                                labelString: 'Value'
                            }
                        }]
                    }
                };

                var config = [];
                config['type'] = "line";
                config['data'] = data;
                config['options'] = setting;

                new Chart($(this), config);
            });
        }
   });

我想尽快解决 谢谢

0 个答案:

没有答案