gpt4 book ai didi

javascript - 使用 json 的 Highcharts 动态向下钻取

转载 作者:行者123 更新时间:2023-11-30 12:27:11 24 4
gpt4 key购买 nike

进行动态向下钻取时出现问题。无法计算使用 highcharts 获取此图表的动态向下钻取数据的代码。请帮忙

<script type="text/javascript">//<![CDATA[ 

$(function () {

// Create the chart
$('#container').highcharts({
chart: {
type: 'pie',
events: {
drilldown: function (e) {
if (!e.seriesOptions) {

var chart = this,
drilldowns = {
'Animals': {
name: 'Animals',
data: [
['Cows', 2],
['Sheep', 3]
]
},
'Fruits': {
name: 'Fruits',
data: [
['Apples', 5],
['Oranges', 7],
['Bananas', 2]
]
},
'Cars': {
name: 'Cars',
data: [
['Toyota', 1],
['Volkswagen', 2],
['Opel', 5]
]
}
},
series = drilldowns[e.point.name];

// Show the loading label
chart.showLoading('Simulating Ajax ...');

setTimeout(function () {
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, series);
}, 1000);
}

}
}
},
title: {
text: 'Async drilldown'
},
xAxis: {
type: 'category'
},

legend: {
enabled: false
},
lang: {
drillUpText: '<< Terug naar {series.name}'
},
plotOptions: {
series: {
borderWidth: 0,
dataLabels: {
enabled: true
}
}
},

series: [{
colorByPoint: true,
data: [{
name: 'Animals',
y: 5,
"drilldown": true
}, {
name: 'Fruits',
y: 2,
drilldown: true
}, {
name: 'Cars',
y: 4,
drilldown: true
}]
}],

drilldown: {
series: []
}
});
});

在我的系列中,我已经有一个 json 数据,用于名称、y 和向下钻取的值。当涉及到 'Animals':{ name: 'Animals', data: ['Cows',2], ['Sheep', 3]]} 中的向下钻取数据时,真的很难。我需要这些的动态数据请帮忙

最佳答案

这部分:

                if (!e.seriesOptions) {
var chart = this,
drilldowns = {
'Animals': {
name: 'Animals',
data: [
['Cows', 2],
['Sheep', 3]
]
},
'Fruits': {
name: 'Fruits',
data: [
['Apples', 5],
['Oranges', 7],
['Bananas', 2]
]
},
'Cars': {
name: 'Cars',
data: [
['Toyota', 1],
['Volkswagen', 2],
['Opel', 5]
]
}
},
series = drilldowns[e.point.name];

// Show the loading label
chart.showLoading('Simulating Ajax ...');

setTimeout(function () {
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, series);
}, 1000);
}

只是一个动态添加向下钻取的简单示例。您可以使用 AJAX 调用,如评论中的建议:

                if (!e.seriesOptions) {
var chart = this,
series = drilldowns[e.point.name];

// Show the loading label
chart.showLoading('Loading...');

$.get('/my/url', e.point.name, function(data) {
chart.hideLoading();
chart.addSeriesAsDrilldown(e.point, data);
// where data is for example:
// { name: 'Cars', data: [ ['Toyota', 1], ['Volkswagen', 2], ['Opel', 5] ] }
});
}

关于javascript - 使用 json 的 Highcharts 动态向下钻取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28969365/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com