Skip to content

Instantly share code, notes, and snippets.

@fabiovalse
Last active August 29, 2015 14:01
Show Gist options
  • Save fabiovalse/a75787d6e2f57cdf2555 to your computer and use it in GitHub Desktop.
Save fabiovalse/a75787d6e2f57cdf2555 to your computer and use it in GitHub Desktop.
Highcharts Bar Chart using TourPedia Data

This bar chart is constructed using highcharts and it uses the TourPedia data. TourPedia contains information about accommodations, restaurants, points of interest and attractions of different places in Europe. Now it provides information about Amsterdam, Barcelona, Berlin, Dubai, London, Paris, Rome and Tuscany. The bar chart shows the amounts of venues grouped by city and venue category.

<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<script src="index.js"></script>
<title>TourPedia Bar Chart</title>
</head>
<body onload="get_data()">
<div id="bar_chart" style="max-width: 500px; max-width: 960px; height: 500px; margin: 0 auto"></div>
</div>
</body>
</html>
function get_data() {
$.getJSON("http://tour-pedia.org/api/getPlacesStatistics", function(data) {
build_bar_chart(data);
});
}
function build_bar_chart(data) {
$('#bar_chart').highcharts({
chart: {
type: 'bar'
},
title: {
text: ''
},
xAxis: {
categories: ['Amsterdam', 'Barcelona', 'Berlin', 'Dubai', 'London', 'Paris', 'Rome', 'Tuscany'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'N° of Resources',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 100,
floating: true,
borderWidth: 1,
backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor || '#FFFFFF'),
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Accommodation',
data: [data['Amsterdam']['accommodation'], data['Barcelona']['accommodation'], data['Berlin']['accommodation'], data['Dubai']['accommodation'], data['London']['accommodation'], data['Paris']['accommodation'], data['Rome']['accommodation'], data['Tuscany']['accommodation']]
}, {
name: 'Attraction',
data: [data['Amsterdam']['attraction'], data['Barcelona']['attraction'], data['Berlin']['attraction'], data['Dubai']['attraction'], data['London']['attraction'], data['Paris']['attraction'], data['Rome']['attraction'], data['Tuscany']['attraction']]
}, {
name: 'Point of Interest',
data: [data['Amsterdam']['poi'], data['Barcelona']['poi'], data['Berlin']['poi'], data['Dubai']['poi'], data['London']['poi'], data['Paris']['poi'], data['Rome']['poi'], data['Tuscany']['poi']]
}, {
name: 'Restaurant',
data: [data['Amsterdam']['restaurant'], data['Barcelona']['restaurant'], data['Berlin']['restaurant'], data['Dubai']['restaurant'], data['London']['restaurant'], data['Paris']['restaurant'], data['Rome']['restaurant'], data['Tuscany']['restaurant']]
}]
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment