2014-06-26 29 views
0

我想要做的是能够动态地呈现图形,从url中定义一组参数。例如http://example.html?team=team1%chartype=pie以编程方式构建不同类型的Highcharts。

这是我的一个简单的“列” http://jsfiddle.net/4mBWg/ 这是我的一个简单的“馅饼” http://jsfiddle.net/YFdKt/

Code block (SO is not letting me post without code) 

编程什么会我需要的是能够接受一个“类型”参数代码代码示例(饼图,图表,行)并能够绘制图表。

仅仅改变“类型”是不够的。看看这两种类型的图我假设plotOptions需要动态构建......我需要做些什么来完成这个任务?

回答

1

如果只是html然后尝试,

// 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 
} 

如果您正在使用PHP的,你可以做到这一点像,

<?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 } ?>