如何在条形图中获取条形图 X 和 Y 的起点
How can I get starting point of X & Y of a bar in Bar Graph
我有一个条形图,我在其中调用了一个 javascript 函数来对条形图上的鼠标单击进行一些操作,我想获得同一条形图的 X 和 Y 轴的起点我点击了,我可以在融合图表中执行此操作吗?如果可以,如何操作?
我用黄色突出显示,我需要根据屏幕显示这些位置。
是的,当您点击条形图时,您可以获得图表维度的 x 和 y 坐标。
您需要使用单击图上任意位置时触发的 FusionCharts "dataPlotClick" 事件 API。然后,在事件函数参数中,您可以使用预定义属性 "chartX" 和 "chartY" 来获取单击点的 x 和 y 坐标。
请查看文档 link 以供参考:https://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-events#dataplotclick-261
另找一个样本fiddle供参考: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();
});
我有一个条形图,我在其中调用了一个 javascript 函数来对条形图上的鼠标单击进行一些操作,我想获得同一条形图的 X 和 Y 轴的起点我点击了,我可以在融合图表中执行此操作吗?如果可以,如何操作?
我用黄色突出显示,我需要根据屏幕显示这些位置。
是的,当您点击条形图时,您可以获得图表维度的 x 和 y 坐标。
您需要使用单击图上任意位置时触发的 FusionCharts "dataPlotClick" 事件 API。然后,在事件函数参数中,您可以使用预定义属性 "chartX" 和 "chartY" 来获取单击点的 x 和 y 坐标。
请查看文档 link 以供参考:https://www.fusioncharts.com/dev/api/fusioncharts/fusioncharts-events#dataplotclick-261
另找一个样本fiddle供参考: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();
});