Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
5536 Zobrazení

I have created a sales dashboard in which I want to show a comparison of the current month's sales with last month's sale using Google Line Charts. 

I have added the following code in my dashboard for testing Google Charts:

  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

<script type="text/javascript">
google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawLineColors); function drawLineColors() {
var data = new google.visualization.DataTable();
data.addColumn('number', 'X');
data.addColumn('number', 'Dogs');
data.addColumn('number', 'Cats'); data.addRows([
[0, 0, 0], [1, 10, 5], [2, 23, 15], [3, 17, 9], [4, 18, 10], [5, 9, 5],
[6, 11, 3], [7, 27, 19], [8, 33, 25], [9, 40, 32], [10, 32, 24], [11, 35, 27],
[12, 30, 22], [13, 40, 32], [14, 42, 34], [15, 47, 39], [16, 44, 36], [17, 48, 40],
[18, 52, 44], [19, 54, 46], [20, 42, 34], [21, 55, 47], [22, 56, 48], [23, 57, 49],
[24, 60, 52], [25, 50, 42], [26, 52, 44], [27, 51, 43], [28, 49, 41], [29, 53, 45],
[30, 55, 47], [31, 60, 52], [32, 61, 53], [33, 59, 51], [34, 62, 54], [35, 65, 57],
[36, 62, 54], [37, 58, 50], [38, 55, 47], [39, 61, 53], [40, 64, 56], [41, 65, 57],
[42, 63, 55], [43, 66, 58], [44, 67, 59], [45, 69, 61], [46, 69, 61], [47, 70, 62],
[48, 72, 64], [49, 68, 60], [50, 66, 58], [51, 65, 57], [52, 67, 59], [53, 70, 62],
[54, 71, 63], [55, 72, 64], [56, 73, 65], [57, 75, 67], [58, 70, 62], [59, 68, 60],
[60, 64, 56], [61, 60, 52], [62, 65, 57], [63, 67, 59], [64, 68, 60], [65, 69, 61],
[66, 70, 62], [67, 72, 64], [68, 75, 67], [69, 80, 72]
]); var options = {
hAxis: {
title: 'Time'
},
vAxis: {
title: 'Popularity'
},
colors: ['#a52714', '#097138']
}; var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<div id="chart_div"></div>

But shows the following errors in browser console on loading the dashboard.


Uncaught ReferenceError: google is not defined
    at <anonymous>:2:33
    at DOMEval (web.assets_common.js:709)
    at domManip (web.assets_common.js:1060)
    at jQuery.fn.init.append (web.assets_common.js:1071)
    at Object.append (web.assets_common.js:3894)
    at Class._appendController (web.assets_backend.js:412)
    at Class._pushController (web.assets_backend.js:429)
    at web.assets_backend.js:415


and


Uncaught (in promise) TypeError: Cannot read property 'tooltip' of undefined
    at Class.<anonymous> (web.assets_common.js:4135)
    at Class.trigger (web.assets_common.js:3942)
    at Class.trigger (web.assets_common.js:3948)
    at Class.destroy (web.assets_common.js:3881)
    at Class.prototype.<computed> [as destroy] (web.assets_common.js:3860)
    at Class.trigger (web.assets_common.js:3942)
    at Class.trigger (web.assets_common.js:3948)
    at Class._pushController (web.assets_backend.js:429)
    at web.assets_backend.js:415


But it is perfectly working when I add it to a simple HTML file. The error occurs in Odoo only. Is there any way to fix this problem?

Avatar
Zrušit
Autor Nejlepší odpověď

Fixed the error by adding the JS file in the static/src/js folder of the module instead of referring it from the web as 

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
led 23
1566
1
pro 23
2810
0
kvě 20
3935
1
dub 19
3631
1
pro 24
2779