Reputation: 346
What I would like to do is to be able to render graphs dynamically giving defined set of parameters from a url. for example http://example.html?team=team1%chartype=pie.
This is my code for a simple 'column' http://jsfiddle.net/4mBWg/ This is my code for a simple 'pie' http://jsfiddle.net/YFdKt/
Code block (SO is not letting me post without code)
programmatically what would I need is to be able to accept a 'type' parameter example (pie, chart, line) and be able to plot the graph.
Simply changing the "type" is not sufficient. Looking at the two types of graphs I am assuming the plotOptions needs to be build dynamically...what would I need to do to accomplish this?
Upvotes: 0
Views: 79
Reputation: 40639
If it is only html
then try,
// http://stackoverflow.com/a/3855394/1817690
var qs = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'));
if(qs['type']) && qs['type']=='pie') {
Pie chart js code goes here
} else if(qs['type'] && qs['type']=='line') {
Line chart js code goes here
}
If you are using PHP
the you can do this like,
<?php if(isset($_GET['type']) && $_GET['type']=='pie') { ?>
Pie chart js code goes here
<?php } else if(isset($_GET['type']) && $_GET['type']=='line') { ?>
Line chart js code goes here
<?php } ?>
Upvotes: 1