Private Sub AddWatermark(ByVal sFileName As String)
Dim watermark As New Watermark
watermark.StandardFrame.Border.Width = 0
watermark.FillEffect.SetImage(Me.MapPathSecure(Me.TemplateSourceDirectory + "\\" + sFileName))
watermark.AlwaysOnTop = False
watermark.HorizontalMargin = 50
watermark.VerticalMargin = 55
watermark.HorzAlign = HorzAlign.Center
watermark.VertAlign = VertAlign.Center
watermark.Interactivity.CustomMapAreaAttributes = "style = 'visibility:hidden'"
chartServerControl1.Watermarks.Add(watermark)
End Sub
Public Function GetScript() As String
Dim sScript As New StringBuilder
sScript.Append("SVGDocument = null" + vbNewLine)
sScript.Append("function Initialize(LoadEvent)" + vbNewLine)
sScript.Append("{" + vbNewLine)
sScript.Append("SVGDocument = LoadEvent.getTarget().getOwnerDocument()" + vbNewLine)
sScript.Append("}" + vbNewLine)
sScript.Append(vbNewLine)
sScript.Append("function ShowWatermark(watermarkID)" + vbNewLine)
sScript.Append("{" + vbNewLine)
sScript.Append("SVGDocument.getElementById(""Watermark_0"").setAttribute('style', 'visibility:hidden')" + vbNewLine)
sScript.Append("SVGDocument.getElementById(""Watermark_1"").setAttribute('style', 'visibility:hidden')" + vbNewLine)
sScript.Append("SVGDocument.getElementById(""Watermark_2"").setAttribute('style', 'visibility:hidden')" + vbNewLine)
sScript.Append("SVGDocument.getElementById(""Watermark_3"").setAttribute('style', 'visibility:hidden')" + vbNewLine)
sScript.Append("SVGDocument.getElementById(""Watermark_4"").setAttribute('style', 'visibility:hidden')" + vbNewLine)
sScript.Append("if (SVGDocument.getElementById(watermarkID))" + vbNewLine)
sScript.Append("{" + vbNewLine)
sScript.Append(" SVGDocument.getElementById(watermarkID).setAttribute('style', 'visibility:visible')" + vbNewLine)
sScript.Append("}" + vbNewLine)
sScript.Append("}" + vbNewLine)
Return sScript.ToString()
End Function
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
chartServerControl1.Background.Interactivity.CustomMapAreaAttributes = "onmouseover = 'ShowWatermark(""Watermark_4"")'"
Dim legend As Legend
Dim random As New Random
legend = CType(chartServerControl1.Legends(0), Legend)
Legend.Mode = LegendMode.Disabled
Dim chart As Chart
chart = CType(chartServerControl1.Charts(0), Chart)
Dim pie As PieSeries
pie = CType(chart.Series.Add(SeriesType.Pie), PieSeries)
chart.MarginMode = MarginMode.Fit
chart.Margins = New RectangleF(10, 20, 80, 70)
pie.Appearance.FillMode = AppearanceFillMode.DataPoints
pie.Add(100 + Random.Next(100), "Toyota", New FillEffect(Color.Red))
pie.Add(100 + Random.Next(100), "VW", New FillEffect(Color.Blue))
pie.Add(100 + Random.Next(100), "Ford", New FillEffect(Color.Green))
pie.Add(100 + Random.Next(100), "Mazda", New FillEffect(Color.Yellow))
pie.Interactivity.CustomMapAreaAttributesMode = SeriesCustomMapAreaAttributesMode.DataPoints
pie.Interactivity.CustomMapAreaAttributes.Add("onmouseover = 'ShowWatermark(""Watermark_0"") '")
pie.Interactivity.CustomMapAreaAttributes.Add("onmouseover = 'ShowWatermark(""Watermark_1"") '")
pie.Interactivity.CustomMapAreaAttributes.Add("onmouseover = 'ShowWatermark(""Watermark_2"") '")
pie.Interactivity.CustomMapAreaAttributes.Add("onmouseover = 'ShowWatermark(""Watermark_3"") '")
pie.PieStyle = PieStyle.Torus
pie.LabelMode = PieLabelMode.Center
AddWatermark("ToyotaLogo.png")
AddWatermark("VWLogo.png")
AddWatermark("FordLogo.png")
AddWatermark("MazdaLogo.png")
AddWatermark("QuestionMark.jpg")
' add header
Dim header As Label
header = chartServerControl1.Labels.AddHeader("Car Sales per Company<br/><font size ='10'>Demonstrates client scripting and embedded images</font>")
header.TextProps.Backplane.Visible = False
header.TextProps.TextType = TextType.XMLFormatted
header.TextProps.Shadow.Type = ShadowType.GaussianBlur
header.TextProps.Offset = New PointF(5, 5)
header.TextProps.FillEffect.SetSolidColor(Color.Black)
header.TextProps.HorzAlign = HorzAlign.Left
header.TextProps.VertAlign = VertAlign.Top
header.HorizontalMargin = 2
header.VerticalMargin = 2
' add an image border
chartServerControl1.Background.FrameType = FrameType.Image
Dim imageFrame As ImageFrame
imageFrame = chartServerControl1.Background.ImageFrame
imageFrame.SetPredefinedFrameStyle(PredefinedImageFrame.Rectangular)
imageFrame.FillEffect.SetGradient(GradientStyle.Horizontal, GradientVariant.Variant1, Color.PaleTurquoise, Color.CadetBlue)
imageFrame.Border.Color = Color.AliceBlue
imageFrame.BackgroundColor = Color.White
' configure background
chartServerControl1.Background.FillEffect.SetSolidColor(Color.White)
Dim svgResponse As New SVGResponse
Dim svgRenderSettings As SVGRenderSettings
svgRenderSettings = svgResponse.SvgRenderSettings
svgRenderSettings.EnableInteractivity = True
svgRenderSettings.EmbeddedScript = GetScript()
svgRenderSettings.EmbedImagesInSVG = True
svgRenderSettings.EmbeddedImageDescription = New JPEGDescription
Dim attributes As New Hashtable
attributes("preserveAspectRatio") = "yMid slice"
attributes("onload") = "Initialize(evt)"
svgRenderSettings.Attributes = attributes
chartServerControl1.ServerConfiguration.DefaultResponse = svgResponse
End Sub