图表JS工具提示和标签宽度为零

时间:2020-02-26 22:06:27

标签: javascript python flask html5-canvas chart.js

工具提示和标签的宽度在localhost上似乎为0,其代码与示例相同: https://i.imgur.com/FJ5nHra.png

我不知道我在做什么错,这是代码: https://pastebin.com/mt9WCdhe

        var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
        var config = {
            type: 'line',
            data: {
                labels: MONTHS,
                datasets: [{
                    label: 'My First dataset',
                    backgroundColor: window.chartColors.red,
                    borderColor: window.chartColors.red,
                    data: randomData(),
                    fill: false,
                }, {
                    label: 'My Second dataset',
                    fill: false,
                    backgroundColor: window.chartColors.blue,
                    borderColor: window.chartColors.blue,
                    data: randomData(),
                }]
            },
            options: {
                responsive: false,
                maintainAspectRatio: false,
                title: {
                    display: true,
                    text: 'Test graph'
                },
                tooltips: {
                    mode: 'index',
                    intersect: false,
                },
                hover: {
                    mode: 'nearest',
                    intersect: false
                },
                scales: {
                    xAxes: [{
                        display: true,
                        scaleLabel: {
                            display: true,
                            labelString: 'Month'
                        }
                    }],
                    yAxes: [{
                        display: true,
                        scaleLabel: {
                            display: true,
                            labelString: 'Value'
                        }
                    }]
                }
            }
        };

        window.onload = function() {
            var ctx = document.getElementById('myChart').getContext('2d');
            window.myLine = new Chart(ctx, config);
        };

使用的示例: https://www.chartjs.org/samples/latest/charts/line/basic.html

控制台上没有错误

1 个答案:

答案 0 :(得分:0)

在Brave Browser上似乎有一个故障,可在URL 0.0.0.0上运行但不在localhost上运行,在localhost上运行正常

相关问题