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

Example with RDF Data Cube & Linechart #8

Merged
merged 5 commits into from
Apr 15, 2019
Merged
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
73 changes: 73 additions & 0 deletions examples/cube-line-highcharts-lib.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/d3-sparql.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/d3-collection.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/d3-dispatch.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/d3-request.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

<script>
// we use some statistical data from the City of Zurich, Switzerland
const endpoint = 'https://ld.stadt-zuerich.ch/query'

const timeline = `
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX qb: <http://purl.org/linked-data/cube#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
SELECT ?time ?bew WHERE { GRAPH <https://linked.opendata.swiss/graph/zh/statistics> {
?obs a qb:Observation ;
qb:dataSet <https://ld.stadt-zuerich.ch/statistics/dataset/BEW-RAUM-ZEIT> ;
<https://ld.stadt-zuerich.ch/statistics/property/ZEIT> ?time ;
<https://ld.stadt-zuerich.ch/statistics/measure/BEW> ?bew ;
<https://ld.stadt-zuerich.ch/statistics/property/RAUM> <https://ld.stadt-zuerich.ch/statistics/code/R30000> .

FILTER(?time >= "1900-01-01"^^xsd:date )
}} ORDER BY ASC(?time)`

d3.sparql(endpoint, timeline).get((error, sparqlData) => {

Highcharts.chart('container', {
chart: {
type: 'line'
},
title: {
text: 'Wirtschaftliche Bevölkerung Stadt Zürich'
},
subtitle: {
text: 'Source: Statistik Stadt Zürich'
},
xAxis: {
categories: sparqlData.map(item => item.time.getFullYear())
},
yAxis: {
title: {
text: 'Wirtschaftliche Bevölkerung (Personen)'
}
},
plotOptions: {
line: {
dataLabels: {
enabled: false
},
enableMouseTracking: true
}
},
series: [{
name: 'Personen',
data: sparqlData.map(item => item.bew.valueOf())
}]
})
})
</script>
</body>

</html>