Page 1 of 1

hotspot_GetHTMLMap

Posted: Fri Mar 27, 2009 5:29 pm
by 13048070
Hi,

When does hotspot_GetHTMLMap fire? I know it fires for each point but when in the sequence of things i.e. only the first time data is added? I've added a hotspot tool to my chart to customise tooltips that appear over points and and I've also added code to restore my chart between postbacks (as demonstrated in the teechart examples). Things worked fine however I have another button on my page that I've used to add annotations to the chart and I need hotspot_GetHTMLMap to fire (as I'm adding new poly areas to mapelements) but it doesn't seem to second time around (i.e. after I'e restored the chart from session). The tooltips that were working disappear. Is its possible to call this event programatically?

[Since posting this I've found that if I remove the existing hotspot tool and add a new one things work as expected. I placed this code in the click event of the button that added the annotations, after the call to redraw the chart. It seems to work but I'm not exactly sure why? :?]

Thanks,

Norman

Posted: Tue Mar 31, 2009 11:15 am
by Marc
Hello Norman,

The hotspot map should correctly re-assign hotpsots to the page map everytime a pageload (page refresh) is called permitting the map to re-align with new data. If that isn't happening then there may be a procedural problem with the Chart/Hotspot tool load.

If that is the case, does the old hotspot map remain active between page loads? (ie. reporting hits where the first pageload hotspots were). If you view the page source, has the html map disappeared? Tag:
HTML <MAP name="MAP .... etc
If you have a small sample project that displays the problem, that you could send us, it would help us debug the problem.

With thanks.
Regards,
Marc

Posted: Tue Mar 31, 2009 4:04 pm
by 13048070
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