问题
I am having a lot of difficulties navigating through amCharts Docs and I cant seem to find the answer to this online.
I am using the amCharts pie chart, and I want a couple of thing to happen when the mouse rolls over a slice, one of those things is to get the slice to pull out what happens when you click a slide in this demo.
This is what I tried according to the doc, but doesn't seem to work:
var pieChartData = [
{
asset: 'Funiture',
marketValue: 50000.00
}, {
asset: 'Cash',
marketValue: 6250.00
}, {
asset: 'Car',
marketValue: 10000.00
}, {
asset: 'Other',
marketValue: 11250.00
}
];
chartAsset = AmCharts.makeChart(
'asset--chart', {
type: 'pie',
dataProvider: pieChartData,
valueField: 'marketValue',
titleField: 'asset',
startEffect: 'easeOutSine',
pulledField: 'pullOut',
//pullOutOnlyOne: true,
// pullOutEffect: 'easeInSine',
responsive: {
enabled: true
},
labelsEnabled: false,
balloon: {
fillAlpha: 0.95,
borderThickness: 1,
borderColor: '#000000',
shadowAlpha: 0,
}
}
);
chartAsset.addListener('rollOverSlice', function(e) {
console.log(e);
/**** Doesn't work: ******/
pieChartData[e.dataItem.index].pullOut = true;
chartAssetAllocation.dataProvider = pieChartData;
chartAssetAllocation.validateData();
});
Can someone please help?
回答1:
You can not trigger the pullout directly, but there's a method to simulate the clicking on the slice. (see clickSlice)
In addition you have to add another listener for leaving a slice, so it will return to its original state.
chartAsset.addListener('rollOverSlice', function(e) {
chartAsset.clickSlice(e.dataItem.index);
});
chartAsset.addListener('rollOutSlice', function(e) {
chartAsset.clickSlice(e.dataItem.index);
});
Here's the working fiddle.
Another approach would be to change just the visualization of the slice using CSS. An example for this can be found here.
来源:https://stackoverflow.com/questions/31150872/amcharts-pie-how-to-get-slice-to-pull-out-on-rolloverslice