如何在循环中使用高图制作多个图表? [英] How to make multiple charts using highcharts in a loop?
问题描述
这是我拥有的相关代码:
This is the relevant code I have:
<script>
titles = <?php echo json_encode($graphTitles)?>;
//Loop through the graphs
for (var graphNO = 0; graphNO < titles.length; graphNO++)
{
//CREATE NEW CONTAINER
var container = document.createElement('div');
document.body.appendChild(container);er);
dates = <?php echo json_encode($recivedDates);?>[titles[graphNO]];
//I EXTRACT A FEW MORE ARRAYS THE SAME METHOD
$(function ()
{
$(container).highcharts({
title: {
text: titles[graphNO]
},
xAxis: {
categories: dates
},
series: [{
type: 'column',
color: 'gold',
name: 'Created Issues',
data: createdIssues.map(Number)
},
//MORE COLUMN'S AND SOME SPLINES. IT ALL WORKS AS EXPECTED
});
});
}
</script>
我不想发布所有代码,只是让它变得凌乱,我希望这段代码要做的是:
I didn't want to post all the code and just make it messy, what I expected this code to do is:
graphNO的值为2,我认为它会循环两次(确实如此),为每个循环创建一个容器(确实如此),然后为它在容器中进行的每个循环绘制不同的图形,制作(但它只是绘制了第二张图).
graphNO has the value of 2, I thought it would loop through twice (which it does), make a container for each loop (which it does), then draw a different graph for each loop it does in the container it just made (but instead it just draws the second graph).
我不知道出什么问题了,但是关于如何解决此问题的任何想法,或者关于如何在循环中制作多个图形的任何想法,都会有很大的帮助.
I don't know whats wrong, but any ideas on how to fix this, or any ideas on how to make multiple graphs in a loop would be great help.
而且,这是我创建的第一个网站,所以一天没有使用javascript,php或html,因此很抱歉,如果确实很明显,我在此上找不到任何东西./p>
Also, this is the first site I'm making so I haven't used javascript, php, or html for more then a day, so sorry if it's really obvious, I couldn't find anything on this though.
推荐答案
我明白了,经过一天无法在网络上尝试复杂的工作之后,我最终想到了如果删除该功能会发生什么而不是:
I got it, after a day of trying complex stuff from around the web that didn't work, I ended up thinking what will happen if I remove the function so rather then:
$(function ()
{
$(container).highcharts({
title: {
我只有:
$(container).highcharts({
title: {
一切都很好.我不知道为什么,可能因为jquery如何处理函数,我不知道,直到一个小时前,我什至不知道我使用的是jquery.但是,如果有人想做类似的事情,它就可以工作,并且可以随时告诉我原因.
And it all worked perfectly. I don't know why, probably because of how jquery deals with functions, I don't know, I didn't even know what I was using was jquery till an hour ago. But it works if anyone ever wants to do something similar, it works, and feel free to tell me why.
这篇关于如何在循环中使用高图制作多个图表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!