尝试在ASP.NET图表中添加交互性时遇到了一些问题。我想在饼图系列中添加点击功能。代码工作正常,但我不确定如何添加点击功能。
protected void populateCategoryPieChart()
{
try
{
Chart2.Visible = true;
Chart2.Titles.Clear();
string query = string.Format("//sensitive data", Convert.ToInt64(sessionDdl.SelectedValue));
DataTable dt = getData(query);
int[] c = new int[dt.Rows.Count];
string[] x = new string[dt.Rows.Count];
int[] y = new int[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
c[i] = Convert.ToInt32(dt.Rows[i][0]);
x[i] = obj.getCategoryByID(Convert.ToInt64(dt.Rows[i][0])).Name;
y[i] = Convert.ToInt32(dt.Rows[i][1]);
}
populateCategoryList(c);
Chart2.Series["Category"].Points.DataBindXY(x, y);
Chart2.Series["Category"].Label = "#VALX";
Chart2.Series["Category"].LabelForeColor = Color.Black;
Chart2.Series["Category"]["PieLabelStyle"] = "Outside";
Title title = new Title("Most Viewed Category", Docking.Top, new Font("Verdana", 13), Color.Black);
Chart2.Titles.Add(title);
Chart2.Legends.Add("Legend1");
Chart2.Legends[0].Enabled = true;
Chart2.Legends[0].Docking = Docking.Bottom;
Chart2.Legends[0].Alignment = StringAlignment.Center;
Chart2.Series["Category"].LegendText = "#VALX (#PERCENT)";
Chart2.DataManipulator.Sort(PointSortOrder.Descending, Chart2.Series["Category"]);
Chart2.Series["Category"].ChartType = SeriesChartType.Pie;
Chart2.ChartAreas["ChartArea2"].Area3DStyle.Enable3D = true;
Chart2.Legends[0].Enabled = true;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
我已按照网站documentation中显示的示例进行操作,但它不适合我,并且没有错误消息。
答案 0 :(得分:-1)
您可以查看此信息,看看它是否符合您的要求:How to create a mouse click event for an item (point) from a Pie chart?