0
您好我正在我的Angularjs應用程序中實現一個圖表,您可以看到這個運動員http://jsfiddle.net/fusioncharts/73xgmacm/
我想實現的目標是將value
屬性更改爲profit
。我怎樣才能做到這一點 ?我想顯示profit
不是值。如何更改Fusionchart數據集中的屬性?
Regards
您好我正在我的Angularjs應用程序中實現一個圖表,您可以看到這個運動員http://jsfiddle.net/fusioncharts/73xgmacm/
我想實現的目標是將value
屬性更改爲profit
。我怎樣才能做到這一點 ?我想顯示profit
不是值。如何更改Fusionchart數據集中的屬性?
Regards
2天后我終於找出答案。問題是,您無法更改Fusionchart
屬性value
,但是您可以在抓取後更改API的屬性。我在獲取API之後使用了一個循環,並用value
替換了'profit'屬性,這樣我創建了圖表。是的我一直忽視的是使用'變量'而不是範圍。如果你看到這個例子,你會明白Example Here。我分享我的代碼可能會幫助其他人。
下面給我的JSON數組我把它叫做tps.json
[
{
"index": "1",
"variantoption": "fan-green",
"company": "sk fans",
"quantity": "650",
"profit": "78296",
"loss": "8457",
"year": "2016"
},
{
"index": "2",
"variantoption": "fan-white",
"company": "al ahmed fans",
"quantity": "450",
"profit": "78296",
"loss": "8457",
"year": "2016"
},
{
"index": "3",
"variantoption": "fan-purple",
"company": "asia fans",
"quantity": "350",
"profit": "78296",
"loss": "8457",
"year": "2016"
},
{
"index": "4",
"variantoption": "fan-yellow",
"company": "falcon fans",
"quantity": "250",
"profit": "78296",
"loss": "8457",
"year": "2016"
}
]
,這裏是我的控制器
$http.get('js/tps.json').success(function (data) {
var chartdata = data;
var arrLength = chartdata.length;
console.log(arrLength);
for (var i = 0; i < arrLength; i++) {
if (chartdata[i]['profit'] && chartdata[i]['index']) {
chartdata[i].value = chartdata[i].profit;
delete chartdata[i].profit;
chartdata[i].label = chartdata[i].index;
delete chartdata[i].index;
console.log(chartdata);
}
}
console.log(chartdata);
FusionCharts.ready(function() {
var tps = new FusionCharts({
type: 'column2d',
renderAt: 'chart-container',
width: '500',
height: '300',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Monthly",
"xaxisname": "Month",
"yaxisname": "Revenue",
"numberprefix": "$",
"showvalues": "1",
"animation": "1"
},
"data" : chartdata
}
});
tps.render();
});
}
);
}
-Stay愚蠢求知若飢