google / google-visualization-issues

288 stars 35 forks source link

Suddenly none of the charts are working ('Undefined' in not an object) #2991

Open vitorlfaria opened 1 year ago

vitorlfaria commented 1 year ago

I'm using Google charts for several months, now it stopped working with the same come that was working last week. Here is the code:

<script type='text/javascript' src='https://www.gstatic.com/charts/loader.js'></script>
<script type='text/javascript'>
    google.charts.load('current', { 'packages': ['corechart', 'bar', 'line'] });
    google.charts.setOnLoadCallback(function () { });

    setTimeout(function () {
        drawChart_economiaMensalGrafico();
        drawChart_consumoAnualGrafico();
    }, 1000);

    function drawChart_economiaMensalGrafico() {
            var data = new google.visualization.arrayToDataTable([
                ['Mês', 'Valor em R$'],
                {economiaMensalGrafico_dados}
            ]);

            var view = new google.visualization.DataView(data);
            view.setColumns([0, 1,
                {
                    calc: 'stringify',
                    sourceColumn: 1,
                    type: 'string',
                    role: 'annotation'
                },
            ]);

            var options = {
                //curveType: 'function',
                colors: ['#01357B'],
                backgroundColor: '#EBEBF2',
                chartArea: { backgroundColor: '#EBEBF2', left: 60, right: 10, top: 20, bottom: 20, width: '100%', height: '100%' },

                title: '',
                legend: { position: 'none' },
                annotations: {
                    style: 'point',
                    stem: { color: 'transparent' },
                    alwaysOutside: false,
                    textStyle: {
                        fontSize: 10,
                        fontName: 'Muli',
                        bold: false,
                    },
                },
                hAxis: {
                    textStyle: {
                        fontSize: 10,
                        fontName: 'Muli',
                        bold: false,
                    },
                },
                vAxis: {
                    textStyle: {
                        fontSize: 10,
                        bold: false
                    },
                },
            };

            //var chart = new google.visualization.ColumnChart(document.getElementById('economiaMensalGrafico'));
            var chart = new google.visualization.LineChart(document.getElementById('economiaMensalGrafico'));

            chart.draw(view, options);
    };
<script/>

Does anyone know what's wrong?

cwsneil commented 1 year ago

I have see a similar issue with our reports. The latest version (52) does not work with custom fontName options. If you remove the fontName: 'Muli', option from the textStyle it should load correctly.

bhimrajg commented 1 year ago

I am also facing same issue. Google charts which were working for last few years, completely stopped rendering and it was throwing an error - "Cannot read properties of undefined (reading 'length')" within a red container error box. This error is being thrown at "chart.draw" method call.

There is recent release of google charts today: https://developers.google.com/chart/interactive/docs/release_notes#current:-april-2023

It looks like that could have triggered this issue, since we are referencing the js library as https://www.gstatic.com/charts/loader.js

I am not sure what caused it to broke the chart functionality and showing that error, but for us - removing the certain fonts specified for chart have worked.

dlaliberte commented 1 year ago

This has been reported by a few people, though why the error is occurring is not at all clear to me since the webfont code should be identical. As a workaround, removing the fontName option works, or loading '51' instead of 'current'. I may rollback the v52 rollout, since there is also a mysterious problem with the CategoryFilter.

vitorlfaria commented 1 year ago

I have see a similar issue with our reports. The latest version (52) does not work with custom fontName options. If you remove the fontName: 'Muli', option from the textStyle it should load correctly.

This worked! Thanks!

dlaliberte commented 1 year ago

The bug still exists in v52 even though you have some workarounds. So reopening. I just rolled back the v52 release, (which may take a couple hours for you to see), but it would be great if more people could test the 'upcoming' version to find out if there are more bugs that need to be fixed before I push out another release.

PBalsdon commented 1 year ago

We also had issues, but we're using the old GWT/imagechart, so we're 10 years out of support anyway... We'll fix our version at 51 and make a plan to migrat/update.