Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for gchart's newer library loader #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ And then in the template:

In this example we are planning to use Google chart, as is evident from the import statement in the view, we import gchart.LineChart. So we must also include the google chart javascript in our template.

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

So the template would look like

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

{{ chart.as_html }}
Expand Down Expand Up @@ -320,9 +320,9 @@ Most of the chart providers support LineChart, BarChart, ColumnChart and PieChar

##### Template

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

{{ chart.as_html }}
Expand Down Expand Up @@ -384,9 +384,9 @@ Most of the chart providers support LineChart, BarChart, ColumnChart and PieChar

##### Template

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.charts.load('current', {packages: ['corechart']});
</script>
{{ chart.as_html }}

Expand Down
7 changes: 6 additions & 1 deletion graphos/templates/graphos/gchart/base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

<script type="text/javascript">
google.setOnLoadCallback(drawChart{{ chart.get_html_id }});
if (typeof google.setOnLoadCallback !== 'undefined') {
google.setOnLoadCallback(drawChart{{ chart.get_html_id }});
console.warn("This version of Google Charts loaded via the jsapi loader is no longer being updated. Please use the new gstatic loader (https://developers.google.com/chart/interactive/docs/basic_load_libs#update-library-loader-code).")
} else {
google.charts.setOnLoadCallback(drawChart{{ chart.get_html_id }});
}
function drawChart{{ chart.get_html_id }}() {
{% block chart_specific_arraytodatatable %}
var data = google.visualization.arrayToDataTable({{ chart.get_data_json|safe }});
Expand Down