单击 FusionCharts 二维柱形图如何更改条形不透明度?
How to change bar opacity upon click of FusionCharts 2D Column Chart?
我试图在点击使用 "dataPlotClick" 事件时切换栏的不透明度。我可以更改不透明度,但是一旦我将鼠标移开栏,不透明度就会变回默认值。
注意:之前有人在 SO 上提出过类似的问题,但似乎没有有效的答案。
我如何利用下面的 dataPlotClick 事件来实现这一点?
events: {
"dataPlotClick": function (evtObj, argObj) {
var i, plotItems;
plotItems = evtObj.sender.jsVars.hcObj.elements.plots[0].items;
plotItems[argObj.dataIndex].graphic.attr("fill-opacity", .2);
}
}
融合图表:
FusionCharts.ready(function () {
var revenueChart = new FusionCharts({
type: 'column2d',
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 (evtObj, argObj) {
var i, plotItems, plotLength;
plotItems = evtObj.sender.jsVars.hcObj.elements.plots[0].items;
plotItems[argObj.dataIndex].graphic.attr("fill-opacity", .2);
}
}
}
}).render();
});
需要在 dataPlotClick FusionCharts API 事件中为已单击的特定数据图设置 alpha 属性。
可以借助 dataPlotClick FusionCharts API 事件中的 dataObj 参数 dataIndex 属性找到特定的数据图索引。
最后借助 FusionCharts setJSONData API 方法设置修改后的 JSON 结构。
请执行下面给定的代码。
FusionCharts.ready(function () {
var topStores = new FusionCharts({
type: 'column2d',
renderAt: 'chart-container',
width: '400',
height: '300',
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(evtObj, argObj) {
var plotNum= argObj.dataIndex;
var data =evtObj.sender.args.dataSource.data;
data[plotNum].alpha="10";
evtObj.sender.setJSONData(evtObj.sender.args.dataSource);
}
}
})
.render();
});
我试图在点击使用 "dataPlotClick" 事件时切换栏的不透明度。我可以更改不透明度,但是一旦我将鼠标移开栏,不透明度就会变回默认值。
注意:之前有人在 SO 上提出过类似的问题,但似乎没有有效的答案。
我如何利用下面的 dataPlotClick 事件来实现这一点?
events: {
"dataPlotClick": function (evtObj, argObj) {
var i, plotItems;
plotItems = evtObj.sender.jsVars.hcObj.elements.plots[0].items;
plotItems[argObj.dataIndex].graphic.attr("fill-opacity", .2);
}
}
融合图表:
FusionCharts.ready(function () {
var revenueChart = new FusionCharts({
type: 'column2d',
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 (evtObj, argObj) {
var i, plotItems, plotLength;
plotItems = evtObj.sender.jsVars.hcObj.elements.plots[0].items;
plotItems[argObj.dataIndex].graphic.attr("fill-opacity", .2);
}
}
}
}).render();
});
需要在 dataPlotClick FusionCharts API 事件中为已单击的特定数据图设置 alpha 属性。
可以借助 dataPlotClick FusionCharts API 事件中的 dataObj 参数 dataIndex 属性找到特定的数据图索引。
最后借助 FusionCharts setJSONData API 方法设置修改后的 JSON 结构。
请执行下面给定的代码。
FusionCharts.ready(function () {
var topStores = new FusionCharts({
type: 'column2d',
renderAt: 'chart-container',
width: '400',
height: '300',
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(evtObj, argObj) {
var plotNum= argObj.dataIndex;
var data =evtObj.sender.args.dataSource.data;
data[plotNum].alpha="10";
evtObj.sender.setJSONData(evtObj.sender.args.dataSource);
}
}
})
.render();
});