我继承了一个小型项目,它工作笨重,实际上实际上很不对劲,它几乎让我te目结舌。Highcharts图显示了265系列,没有数据更新到类别和系列
我所试图做的是控制什么是显示在图表上,这样我可以导出最终的图形和数据集。该脚本基本上在MySQL中执行数据透视查询,然后在生成的页面上通过时间帧增量分割数据。单击各个复选框会更改是否超过时间范围的一部分。但是,每次我更改图表内容时,它都会在底部显示一系列从1到265的数字,并且没有数据。我有代码吐出两个类别的x轴和系列数据传递,以确保我没有失去我的想法。
function setDynamicChart(chartCategories, chartData){
alert(chartCategories + '\n' + chartData);
$('#container123').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Fundamental Company Analysis'
},
plotOptions: {
line: {
dataLabels: {
enabled: false
},
enableMouseTracking: true
}
},
xAxis: {
categories: chartCategories
},
series: chartData
});
}
是改变graphdata
function regen(){
var datacount = parseInt(document.f1.datacount.value);
var linecount = parseInt(document.f1.linecount.value);
var xnames = [];
mst = document.getElementById('metrics').value;
var metricnames = mst.split(",");
var sseries = "";
//rebuild
cats = "";
for(a = 1; a <= linecount; a++){
xnames[a] = document.getElementById('name_'+a).value;
for(b = 1; b <= metricnames.length; b++){
temp = ""
for(z = 1; z <= datacount; z++){
if(document.getElementById('set_'+z).checked){//deals with datacount
if(a==1 && b==1)
cats = cats + "'" + document.getElementById('TimeFrame'+z).value + "',";
temp = temp + document.getElementById('data_' + a + '_' + z + '_' + b).value + ",";
}
}
sseries = sseries + "{ name: '" + xnames[a] + "-" + metricnames[b-1] + "', data: [" + removeLastComma(temp) + "]}, "
}
}
cats = '[' + removeLastComma(cats) + ']';
sseries = '[' + removeLastComma(sseries) + ']';
//setDynamicChart(eval("cats"),eval("sseries"));
setDynamicChart(cats,sseries);
}
是重新生成曲线图中的代码的功能。
下面是代码示例产生
<form name='f1' id='f1'>
<div id='mytablee_data'>
<input id='set_1' type='checkbox' value='1' onclick='regen();' checked='checked' style='top:-2px;position:relative;vertical-align: middle;margin-right: 9px'/>
<input type='hidden' value='2005FY' id='TimeFrame1'>
2005FY Data
<table id='mytablee_1' class='tablesorter' border='1'>
<thead><tr><th align='center'>Company</th><th align='center'>Accounts Payable</th><th align='center'>Accounts Receivable</th></tr>
</thead>
<tbody>
<tr align='right'><td style='width:auto' align='left'>Advanced Micro Devices</td><td style='width:auto'>856</td><td style='width:auto'>0</td></tr>
<tr align='right'><td style='width:auto' align='left'>Amazon</td><td style='width:auto'>1366</td><td style='width:auto'>0</td></tr></tbody></table><p></p>
<input id='set_2' type='checkbox' value='2' onclick='regen();' checked='checked' style='top:-2px;position:relative;vertical-align: middle;margin-right: 9px'/>
<input type='hidden' value='2006FY' id='TimeFrame2'>
2006FY Data
<table id='mytablee_2' class='tablesorter' border='1'>
<thead><tr><th align='center'>Company</th><th align='center'>Accounts Payable</th><th align='center'>Accounts Receivable</th></tr>
</thead>
<tbody>
<tr align='right'><td style='width:auto' align='left'>Advanced Micro Devices</td><td style='width:auto'>1338</td><td style='width:auto'>0</td></tr>
<tr align='right'><td style='width:auto' align='left'>Amazon</td><td style='width:auto'>1816</td><td style='width:auto'>-103</td></tr></tbody></table><p></p>
<input id='set_3' type='checkbox' value='3' onclick='regen();' checked='checked' style='top:-2px;position:relative;vertical-align: middle;margin-right: 9px'/>
<input type='hidden' value='2007FY' id='TimeFrame3'>
2007FY Data
<table id='mytablee_3' class='tablesorter' border='1'>
<thead><tr><th align='center'>Company</th><th align='center'>Accounts Payable</th><th align='center'>Accounts Receivable</th></tr>
</thead>
<tbody>
<tr align='right'><td style='width:auto' align='left'>Advanced Micro Devices</td><td style='width:auto'>1009</td><td style='width:auto'>0</td></tr>
<tr align='right'><td style='width:auto' align='left'>Amazon</td><td style='width:auto'>2795</td><td style='width:auto'>-255</td></tr></tbody></table><p></p>
<input type='hidden' name='linecount' value='2'>
<input type='hidden' name='datacount' value='3'>
<input type='hidden' id='metrics' value="Accounts Payable,Accounts Receivable">
<input type='hidden' value='Advanced Micro Devices' id='name_1'>
<input type='hidden' value='856' id='data_1_1_1'>
<input type='hidden' value='1338' id='data_1_2_1'>
<input type='hidden' value='1009' id='data_1_3_1'>
<input type='hidden' value='0' id='data_1_1_2'>
<input type='hidden' value='0' id='data_1_2_2'>
<input type='hidden' value='0' id='data_1_3_2'>
<input type='hidden' value='Amazon' id='name_2'>
<input type='hidden' value='1366' id='data_2_1_1'>
<input type='hidden' value='1816' id='data_2_2_1'>
<input type='hidden' value='2795' id='data_2_3_1'>
<input type='hidden' value='0' id='data_2_1_2'>
<input type='hidden' value='-103' id='data_2_2_2'>
<input type='hidden' value='-255' id='data_2_3_2'></div>
</form>
的数据元素由公司,时间表,指标去,以便轻松地分析了选择改变
非常感谢。我尝试了你的方式,我得到了第一个类别,以及X轴上的数字2 - 9。我看了控制台日志,并且我得到了 Array [“2005FY”,“2007FY”] Array [对象,对象,对象,对象] 所以第一个注册正确,但其他的不是。我会检查语法,看看是否需要引号 – user2105186 2015-02-09 15:27:08
它看起来像你有复制和粘贴我的代码到你的网页的问题..我看到#125线的差异。 – 2015-02-09 16:03:39
我认为第二组需要传递JSON格式。我进行了修改,并获得了系列名称以正确显示,但没有显示数据。 我已经修改了代码是本 变种itemx = { \t \t \t名: “ '” + xnames [α] + “ - ” + metricnames并[b-1] + “'”, \t \t数据:“[”+ temp +“]” \t \t \t}; \t \t \t sseries.push(itemx); 但数据片断 – user2105186 2015-02-09 16:17:16