我有一个条形图,其中我调用一个javascript函数来对条形图的鼠标单击进行一些操作,我想获得我单击的同一条形图的X和Y轴的起点,我可以这在融合图中,如果是,怎么办?
我用黄色突出显示,我需要根据屏幕的位置。
答案 0 :(得分:3)
是的,当您点击条形图时,可以获得关于图表尺寸的x和y坐标。
您需要使用FusionCharts“ dataPlotClick”事件API,该事件API在您单击图中的任意位置时都会触发。然后,在事件函数参数中,可以使用预定义的属性“ chartX”和“ chartY”来获取单击点的x和y坐标。
请查看文档链接以获取参考:https://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-events#dataplotclick-261
还找到一个样本提琴供参考:https://jsfiddle.net/mf1qh9ku/1/
FusionCharts.ready(function() {
var revenueChart = new FusionCharts({
type: 'bar2d',
renderAt: 'chart-container',
width: '500',
height: '350',
dataFormat: 'json',
dataSource: {
"chart": {
"caption": "Monthly revenue for last year",
"subCaption": "Harry's SuperMart",
"xAxisName": "Month",
"yAxisName": "Revenue (In USD)",
"numberPrefix": "$",
"paletteColors": "#0075c2",
"bgColor": "#ffffff",
"borderAlpha": "20",
"canvasBorderAlpha": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"placevaluesInside": "1",
"rotatevalues": "1",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14"
},
"data": [{
"label": "Jan",
"value": "420000"
}, {
"label": "Feb",
"value": "810000"
}, {
"label": "Mar",
"value": "720000"
}, {
"label": "Apr",
"value": "550000"
}, {
"label": "May",
"value": "910000"
}, {
"label": "Jun",
"value": "510000"
}, {
"label": "Jul",
"value": "680000"
}, {
"label": "Aug",
"value": "620000"
}, {
"label": "Sep",
"value": "610000"
}, {
"label": "Oct",
"value": "490000"
}, {
"label": "Nov",
"value": "900000"
}, {
"label": "Dec",
"value": "730000"
}]
},
"events": {
"dataPlotClick": function(eventObj, dataObj) {
alert("X : " + eventObj.data.chartX + ", Y : " + eventObj.data.chartY);
}
}
}).render();
});