Skip to content

Instantly share code, notes, and snippets.

@badosa
Last active November 21, 2019 05:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save badosa/ce3bc50e7b569bef24f8 to your computer and use it in GitHub Desktop.
Save badosa/ce3bc50e7b569bef24f8 to your computer and use it in GitHub Desktop.
fromCSV() example
<!DOCTYPE html>
<!--[if lt IE 7]><html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]><html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]><html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
<head>
<title>Visual + JSON-stat: line chart from CSV</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!-- DO NOT DO THIS IN PRODUCTION -->
<!-- js.org and json-stat.org ARE NOT CDNs! Link to your own copies or to a CDN. -->
<link href="https://visual.js.org/visual.css" rel="stylesheet" type="text/css" />
<script src="https://visual.js.org/lazyvisualsetup.js"></script>
<!-- /DO NOT DO THIS IN PRODUCTION -->
<script src="https://cdn.jsdelivr.net/combine/npm/jsonstat@0.13.13,npm/jsonstat-utils@2.5.5"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<body>
<section id="visual" class="visual"></section>
<script>
$.ajax( { url: "https://data.ssb.no/api/v0/dataset/1086.csv?lang=en" } )
.done(function( csv ) {
console.log(csv);
console.log(JSONstatUtils.fromCSV( csv ));
console.log(JSONstat( JSONstatUtils.fromCSV( csv ) ));
var
ds=JSONstat( JSONstatUtils.fromCSV( csv ) ),
cpi=ds.Data( { "contents" : "12-month rate (per cent)" }, false ),
time=ds.Dimension( "month" ).id.map( function( t ){
return t.replace( /M/, "" );
});
;
visual({
lang: "en",
title: "Consumer Price Index",
footer: "Source: Statistics Norway. Dataset 1086.",
geo: "Norway",
unit: { "symbol" : "%" },
grid: { point: 0, shadow: 0 },
axis: { x: false },
dec: 1,
type: "tsline",
time: time,
data: [ { label: "12-month rate", val: cpi } ]
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment