我有一个极地散点图,我有一个相同的图例,如果你知道点击其中一个图例项目,与该项目相关的点将隐藏在图表中。所以我要做的就是点击事件,我想从我的代码中调用web方法。以下是我正在使用的代码
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
crossDomain: true,
dataType: "json",
url: "DataPolarScatter.aspx/GetDescription",
data: '{ Code: "' + SelectedCode + '" }',
success: function (val) {
var Data = $.parseJSON(val.d);
var xaxis = 0;
var yaxis = 0;
for (i = 0; i < Data.length; i++) {
chartFilterDataSymp.push({ "Code": Data[i].Code, "Name": Data[i].Name, "Count": Data[i].Count });
grphArr.push({ "Code": Data[i].Code, "title": Data[i].Code + "[" + Data[i].Name + "]" + ", Count: " + Data[i].Count, "balloonText": Data[i].Code + "[" + Data[i].Name + "]" + ", Count: " + Data[i].Count, "bullet": "round", "lineAlpha": 0, "series": [[xaxis, yaxis]] });
xaxis = xaxis + 100;
yaxis = yaxis + 4;
}
var chartdivRadar = AmCharts.makeChart("chartdivRadar", {
type: "radar",
dataProvider: chartFilterDataSymp,
categoryField: "Name",
startDuration: 2,
valueAxes: [{
axisAlpha: 0.15,
minimum: 0,
dashLength: 3,
axisTitleOffset: 20,
gridCount: 5,
radarCategoriesEnabled: false
}],
graphs: [{
valueField: "Count",
bullet: "round",
balloonText: "[[category]]: [[value]]"
}],
"export": {
"enabled": true,
"libs": {
"autoLoad": false
}
}
});
//var legendRadar = new AmCharts.AmLegend();
//chartdivRadar.addLegend(legendRadar, "legendRadar");
//// WRITE
//chartdivRadar.write("chartdivRadar");
chartdvPolarSctr = AmCharts.makeChart("chartdivPolarScatter", {
type: "radar",// theme: "light",
dataProvider: chartFilterDataSymp,
startDuration: 1,
valueAxes: [{
"axisAlpha": 0.15,
"dashLength": 3,
"axisTitleOffset": 20,
"gridCount": 5,
"gridType": "circles",
"minimum": 0
}],
polarScatter: {
"minimum": 0,
"maximum": 5000,
"step": 1
},
graphs: grphArr
});
chartdvPolarSctr.addListener("clickGraphItem", function (event) {
// debugger;
//alert(event.item.dataContext);
//alert(event.item.values.value);
//alert(event.item.category);
var url = "TopTenCharts.aspx?Code=" + "78321";
window.location.href = url;
});
var legendPolarScatter = new AmCharts.AmLegend();
legendPolarScatter.addListener("clickLegendItem", function (event) {
$.ajax({
type: "POST",
url: "DataPolarScatter.aspx/AddRemoveCode",
data: event.item.category,
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function (msg) {
alert('Code removed');
},
error: function (e) {
alert('Error');
}
});
});
chartdvPolarSctr.addLegend(legendPolarScatter, "legendPolarScatter");
// WRITE
chartdvPolarSctr.write("chartdivPolarScatter");
}
});
那么是否可以为传说添加一个监听器,如果是,那将是什么事件?
答案 0 :(得分:0)
所以我使用了错误的事件,因此我的代码不起作用。因为我在隐藏项目时需要动作,所以我使用了hideItem事件
这是指向可用于图例的事件列表的链接:https://docs.amcharts.com/3/javascriptcharts/AmLegend
legendPolarScatter.addListener("hideItem", function (event) {
$.ajax({
type: "POST",
url: "DataPolarScatter.aspx/AddRemoveCode",
data: '{ Code: "' + event.dataItem.title + '" }',
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function (msg) {
//alert('Code removed');
},
error: function (e) {
//alert(e.error);
}
});
});