How to create a mouse click event for an item (poi

2019-08-31 01:42发布

问题:

I am creating an ASP.NET/C# website

I used the ASP.NET 4.0 Chart control, to draw a Pie chart.

Is there a way to create an action for when the user clicks an item (point) with the mouse? For example, an item is clicked, it's color change, or the user gets the item's name or...

Thank you for any help

Is there also a way to create a mouse over event on an item?

回答1:

sure there are some options for interactivity on both ASP.NET and Windows Forms.

check here: Interactivity (Chart Controls)

there is an example for the click on the legend:

using System.Web.UI.DataVisualization.Charting;
...
// Set the legend cell to an image showing selection cleared
Chart1.Legends[0].CustomItems[0].Cells[0].Image = "./cleared.png";
Chart1.Legends[0].CustomItems[0].Cells[0].PostBackValue = "item 1";
// Add an ImageMapEventHandler to the Chart.Click event
this.Chart1.Click += new ImageMapEventHandler(this.Chart1_Click);
...
// Change the selection image when the user clicks on the legend cell
private void Chart1_Click(object sender, System.Web.UI.WebControls.ImageMapEventArgs e)
{
   if (e.PostBackValue == "item 1")
   {
      LegendCell cell = Chart1.Legends[0].CustomItems[0].Cells[0];
      cell.Image = (cell.Image == "./cleared.png") ? "./selected.png" : "./cleared.png";
   }
}

and also one for the mouseover:

onmouseover=\"DisplayTooltip(' <img src=DetailedChart.aspx />');\"