Meteogram_GT
author(s): GM 2022
by quito96
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/pattern-fill.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/windbarb.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript"></script>
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
<figure class="highcharts-figure">
<div id="container">
<div id="loading">
<i class="fa fa-spinner fa-spin"></i> Loading data from external source
</div>
</div>
</figure>
CSS
#container {
max-width: 800px;
min-width: 380px;
height: 310px;
margin: 0 auto;
}
#loading {
margin-top: 100px;
text-align: center;
}
.highcharts-figure,
.highcharts-data-table table {
min-width: 350px;
max-width: 800px;
margin: 1em auto;
}
.highcharts-data-table table {
font-family: Verdana, sans-serif;
border-collapse: collapse;
border: 1px solid #ebebeb;
margin: 10px auto;
text-align: center;
width: 100%;
max-width: 500px;
}
.highcharts-data-table caption {
padding: 1em 0;
font-size: 1.2em;
color: #555;
}
.highcharts-data-table th {
font-weight: 600;
padding: 0.5em;
}
.highcharts-data-table td,
.highcharts-data-table th,
.highcharts-data-table caption {
padding: 0.5em;
}
.highcharts-data-table thead tr,
.highcharts-data-table tr:nth-child(even) {
background: #f8f8f8;
}
.highcharts-data-table tr:hover {
background: #f1f7ff;
}
JavaScript
/**
* This is a complex demo of how to set up a Highcharts chart, coupled to a
* dynamic source and extended by drawing image sprites, wind arrow paths
* and a second grid on top of the chart. The purpose of the demo is to inpire
* developers to go beyond the basic chart types and show how the library can
* be extended programmatically. This is what the demo does:
*
* - Loads weather forecast from www.yr.no in form of a JSON service.
* - When the data arrives async, a Meteogram instance is created. We have
* created the Meteogram prototype to provide an organized structure of the
* different methods and subroutines associated with the demo.
* - The parseYrData method parses the data from www.yr.no into several parallel
* arrays. These arrays are used directly as the data option for temperature,
* precipitation and air pressure.
* - After this, the options structure is built, and the chart generated with
* the parsed data.
* - On chart load, weather icons and the frames for the wind arrows are
* rendered using custom logic.
*/
function Meteogram(json, container) {
// Parallel arrays for the chart data, these are populated as the JSON file
// is loaded
this.symbols = [];
this.precipitations = [];
this.precipitationsError = []; // Only for some data sets
this.winds = [];
this.temperatures = [];
this.pressures = [];
// Initialize
this.json = json;
this.container = container;
// Run
this.parseYrData();
}
/**
* Mapping of the symbol code in yr.no's API to the icons in their public
* GitHub repo, as well as the text used in the tooltip.
*
* https://api.met.no/weatherapi/weathericon/2.0/documentation
*/
Meteogram.dictionary = {
clearsky: {
symbol: '01',
text: 'Clear sky'
},
fair: {
symbol: '02',
text: 'Fair'
},
partlycloudy: {
symbol: '03',
text: 'Partly cloudy'
},
cloudy: {
symbol: '04',
...