Question

In a .NET C# line chart, for Every Empty Point marker, I want to display a popup when a user hovers the mouse over the marker.

It seems simple to add a simple string as a tooltip, but I need to create a small popup box for each empty point marker which contains a few lines of information, and an image.

I'll be thankful for any advice!

Was it helpful?

Solution

MsCharts generate a map overlay (a set of map areas) over the chart that you can customize in order to get custom hover events. Chart exposes CustomizeMapAreas event that you can subscribe on like this:

    protected void BindMapAreaEventHandlers()
    {
        this.CustomizeMapAreas += new EventHandler<CustomizeMapAreasEventArgs>(CustomizeMapAreasHandler);
    }

    private void CustomizeMapAreasHandler(object sender, CustomizeMapAreasEventArgs e)
    {
    }

Now call your BindMapAreaEventHandlers() function during the initialization of the chart and put a logic that displays a popup on hover into a CustomizeMapAreasHandler, where you can iterate through all map items generated for the chart.

private void CustomizeMapAreasHandler(object sender, CustomizeMapAreasEventArgs e)
{
    foreach (MapArea item in e.MapAreaItems)
    {
        // any custom logic to change onHover for MapArea.
    }
}

In order for all map areas to be generated correctly, I'd recommend to set-up non-null tooltips for all series when adding series to the chart and then change them back to null in CustomizeMapAreasHandler. This simple trick tells MsCharts that map areas for all series are important, otherwise it will generate map areas for legend only.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top