1-DAV-202 Data Management 2024/25

Materials · Introduction · Rules · Contact
· Please fill in the following survey


Difference between revisions of "Ljavascript"

From MAD
Jump to navigation Jump to search
Line 22: Line 22:
 
* You can either call `google.charts.load("current", {packages:["calendar"]});` separatelly for each package or list all packages in one line in one array.
 
* You can either call `google.charts.load("current", {packages:["calendar"]});` separatelly for each package or list all packages in one line in one array.
 
* After loading of library is done, this calls you function named `drawChart` `google.charts.setOnLoadCallback(drawChart);`. You can either draw multiples charts in one fuction, or call multiple function (you need to set multiple callbacks). Be careful to not name functions with same name.
 
* After loading of library is done, this calls you function named `drawChart` `google.charts.setOnLoadCallback(drawChart);`. You can either draw multiples charts in one fuction, or call multiple function (you need to set multiple callbacks). Be careful to not name functions with same name.
 +
* Each chart needs its own element with different ID. That's this thing: `<div id="chart_div" style="width: 900px; height: 500px;"></div>`. Refferenced here: `new google.visualization.Histogram(document.getElementById('chart_div'));`
 
* Follow instructions here: [https://developers.google.com/chart/interactive/docs/basic_multiple_charts?hl=en]
 
* Follow instructions here: [https://developers.google.com/chart/interactive/docs/basic_multiple_charts?hl=en]

Revision as of 08:48, 4 April 2022

HWjavascript


In this lecture we will extend the website from the previous lecture with interactive visualizations written in JavaScript. We will not cover details of the JavaScript programming language, only use visualization contained in the Google Charts library.

Your goal is to take examples from the documentation and tweak them for your purposes.

A short explanation how things fit together:

  • Your Python server (in Flask) produces a HTML page with some content.
  • You can embed some Javascript code inside the HTML. This code will be run in browser.

Tips:

Merging multiple examples together:

  • You need to include `<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>` just once. This is similar to `import` in python.
  • You can either call `google.charts.load("current", {packages:["calendar"]});` separatelly for each package or list all packages in one line in one array.
  • After loading of library is done, this calls you function named `drawChart` `google.charts.setOnLoadCallback(drawChart);`. You can either draw multiples charts in one fuction, or call multiple function (you need to set multiple callbacks). Be careful to not name functions with same name.
  • Each chart needs its own element with different ID. That's this thing: `
    `. Refferenced here: `new google.visualization.Histogram(document.getElementById('chart_div'));`
  • Follow instructions here: [1]