Hi Marc,
Apologies but I couldn't post the complete sample project but see below for an illustration of what's going on. Essentially cmdPlotData adds data to the chart and cmdShowAnnotations shows/hides annotations.
The page containing the chart is actually a user control (i.e. .ascx) which is added dynamically to a web page at runtime. The user control supports partial rendering which may have something to do with it?
To answer:
has the html map disappeared?
No, the map is still there.
If I leave out the line:
Code: Select all
cmdShowAnnotations_Click(sender, e)
in the cmdPlotData_Click event then the tooltips continue to work. If I include this line then I have to reinitialize the hotspot tool.
Code: Select all
Private annotations As New Dictionary(Of Integer, Steema.TeeChart.Tools.Annotation)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
InitializeHotSpotTool
If Not Page.IsPostBack Then
' Remove existing session stored Chart
Session.Remove("tmpChart")
' Plot data
cmdPlotData_Click(sender, e)
Else
' Restore from session if the postback was caused by a control on another user control or if the chart data doesn't need to change
Dim ctrl As Control = GetPostBackControl(Me.Page) ' returns control that caused postback
If Not (ctrl Is Nothing) AndAlso Not (Session("tmpChart") Is Nothing) Then
If Not ctrl.ClientID.StartsWith("myParentCtrlPrefix") OrElse _
ctrl.ID <> "cmdPlotData" AndAlso _
ctrl.ID <> "cmdSomeOtherButton" Then
Dim tmpChart As MemoryStream = New MemoryStream()
' Retrieve the session stored Chart
tmpChart = CType(Session("tmpChart"), MemoryStream)
tmpChart.Position = 0
' Import saved Chart
WebChart.Chart.Import.Template.Load(tmpChart)
End If
Else
' Plot data
cmdPlotData_Click(sender, e)
End If
End If
End Sub
Protected Sub cmdPlotData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdPlotData.Click
' Get new data from database
' Add chart series and chart data
' Not shown for brevity
' Draw annotations
cmdShowAnnotations_Click(sender, e) ' if omitted tooltips continue to appear
' Export Chart to a MemoryStream template
Dim tmpChart As MemoryStream = New MemoryStream()
WebChart.Chart.Export.Template.Save(tmpChart)
' Save template to a Session variable
Session.Add("tmpChart", tmpChart)
End Sub
Protected Sub cmdShowAnnotations_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdShowAnnotations.Click
' Get data from database
' Remove any existing chart annotation tools
' For each row of data add new chart annotation tool and populate annotations dictionary object
' Not shown for brevity
Dim bmp As Drawing.Bitmap = WebChart.Chart.Bitmap(w, h)
InitializeHotSpotTool ' if omitted hotspots dont work
End Sub
Protected Sub WebChart_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles WebChart.AfterDraw
' Iterate annotations and position accordingly using pixel coordinates
For Each kvp As KeyValuePair(Of Integer, Steema.TeeChart.Tools.Annotation) In annotations
' Not shown for brevity
Next
End Sub
Private Sub hotspot_GetHTMLMap(ByVal sender As Steema.TeeChart.Tools.SeriesHotspot, ByVal e As Steema.TeeChart.Tools.SeriesHotspotEventArgs)
' Create mouseover hints for series data
Dim XVal As String = e.PointPolygon.Title
XVal = Date.FromOADate(e.Series.XValues.Value(e.PointPolygon.ValueIndex)).ToString()
e.PointPolygon.Title = "Date/Time: " & XVal & vbCrLf & _
"Value: " & e.Series.YValues.Value(e.PointPolygon.ValueIndex).ToString()
' Create mouseover hint for each annotation
If ((e.Series Is WebChart.Chart(0)) AndAlso (e.PointPolygon.ValueIndex = 0)) Then
Dim mapElements As String = String.Empty
For Each kvp As KeyValuePair(Of Integer, Steema.TeeChart.Tools.Annotation) In annotations
' Add to mapElements remembering about lead "<"
' Not shown for brevity
Next
If mapElements <> String.Empty Then
CType(sender, Steema.TeeChart.Tools.SeriesHotspot).MapElements = mapElements
End If
End If
End Sub
Private Sub InitializeHotSpotTool()
' Iterate chart tools and remove any existing hotspot tools
' Not shown for brevity
' Add hotspot tool
Dim seriesHotspotTool As New Steema.TeeChart.Tools.SeriesHotspot(ch)
With seriesHotspotTool
.HelperScript = Steema.TeeChart.Tools.HotspotHelperScripts.Annotation
.HotspotCanvasIndex = 499
.MapAction = Steema.TeeChart.Styles.MapAction.Script
.MapElements = ""
End With
AddHandler seriesHotspotTool.GetHTMLMap, AddressOf hotspot_GetHTMLMap
End Sub
Thanks,
Norman