在我的高中, 系列:[{ 类型:'馅饼', 名称:'浏览器分享', 数据:[ ['个人 - 左派',30], ] 这段代码对我来说很好。如果我从隐藏元素中获取参数,比如
系列:[{ 类型:'馅饼', 名称:'浏览器分享', 数据:[ $('#图表&#39)。VAL() ] 它对我不起作用。如果有人知道答案,请建议。
答案 0 :(得分:0)
首先尝试将其传递给数组,如果可以的话,尝试将其传递给变量。
EG:
var forMyGraph = $('#graph').val();
然后将其插入图表
[{
type: 'pie',
name: 'Browser share',
data: [ forMyGraph ]
}]
编辑:我的jQuery中的一些片段传递给Highchart:
第1步:我为我想要的两个值创建一个新数组,包括切片的名称和该切片的值
var Titles = new Array();
var Totals = new Array();
第2步:然后我使用jQuery浏览我的隐藏表来获取我的值并将它们推送到我的数组中:
$("#GridView2 tr:has(td)").each(function () {
var cell = $(this).find("td:eq(1)");
Titles.push(cell.html());
// it receives something like "Title1, Title2, Title3"
});
$("#GridView2 tr:has(td)").each(function () {
var cell2 = $(this).find("td:eq(2)");
var scell2 = cell2.text();
var sscell2 = scell2.split(/[a-zA-Z,\s]/).join("").slice(0, -2);
Totals.push(sscell2);
// don't worry about the splitting and slicing, I needed to use Regex to remove some stuff
第3步:然后我设置了不同的标题:
//I do this by selecting my items out of the array I built
Title1 = Titles[0];
Title2 = Titles[1];
Title3 = Titles[2];
Title4 = Titles[3];
Title5 = Titles[4];
Title6 = Titles[5];
我的不同总数:
//Back to Int for Graphs, notice how I now parseInt() here, Highcharts are very fussy
Total1 = parseInt(Totals[0]);
Total2 = parseInt(Totals[1]);
Total3 = parseInt(Totals[2]);
Total4 = parseInt(Totals[3]);
Total5 = parseInt(Totals[4]);
Total6 = parseInt(Totals[5]);
然后终于,就像你做的那样,我将数据插入到我的图表中:
series: [{
name: 'Total',
data: [
[Title1, Total1],
[Title2, Total2],
{
name: Title3,
y: Total3,
sliced: true,
selected: true
},
[Title4, Total4],
[Title5, Total5],
[Title6, Total6]
]
}, ]
我希望这会对你有所帮助:)如果你有疑问,请告诉我。