今天在网上看到一个强大SilverLight图表控件:
链接网址:http://visifire.com/
我用的版本是:3.6.8
代码:
引用SLVisifire.Charts.dll
Imports Visifire.Charts
Imports Visifire.Commons
Me.LayoutRoot.Children.Clear()
Dim chart As New Chart
chart.Width = 450.0
chart.Height = 300.0
'去除水印效果,如果没有购买产品,水印是去不掉的
'如果想去掉水印,可以添加一个StackPanel遮罩层将水印去掉
chart.Watermark = False
'是否添加3D效果,默认非3D效果
chart.View3D = True
'图表皮肤,有3种默认皮肤,Theme1,Theme2,Theme3
'注:未实现枚举,有待进一步改进
chart.Theme = "Theme1"
'图表颜色集合
chart.ColorSet = "VisiGreen"
'图表的工具栏是否可用,现在默认只有一个保存为图片的功能
chart.ToolBarEnabled = True
chart.ScrollingEnabled = True
chart.AnimatedUpdate = True
chart.CornerRadius = New CornerRadius(7.0)
chart.ShadowEnabled = True
'chart标题
Dim title As New Title
title.Text = "Visifire图表演示"
title.Padding = New Thickness(0.0, 10.0, 15.0, 10.0)
chart.Titles.Add(title)
Dim tip = New Visifire.Charts.ToolTip()
tip.VerticalAlignment = VerticalAlignment.Bottom
tip.Text = "Visifire图表演示Tip"
chart.ToolTips.Add(tip)
Dim legend = New Legend()
chart.Legends.Add(legend)
Dim axi As New Axis
axi.Title = "X轴参数代表含义"
'X轴刻度类型
axi.IntervalType = Visifire.Charts.IntervalTypes.Number
'X轴刻度间隔
axi.Interval = 2.0
chart.AxesX.Add(axi)
Dim axiY As New Axis
'Y轴参数最小值
axiY.AxisMinimum = 1
'Y轴参数后缀
axiY.Suffix = ".00"
'y轴参数前缀
axiY.Prefix = "数字:"
axiY.Title = "Y轴参数代表含义"
chart.AxesY.Add(axiY)
'图表中的单个数据线
Dim dataSeries As New DataSeries
'单个数据线
dataSeries.RenderAs = Visifire.Charts.RenderAs.Column
dataSeries.LegendText = "数据线1"
Dim count As Integer = 6
Dim random As New Random()
For i As Integer = 0 To count - 1
'单个数据线中的数据点
Dim dataPoint As New DataPoint
dataPoint.YValue = random.Next(1, 100)
dataPoint.ToolTipText = (i + 1).ToString + "-" + dataPoint.YValue.ToString()
'AddHandler dataPoint.MouseLeftButtonUp, New RoutedEventHandler(AddressOf dataPointMouseLeftBtnUp)
dataSeries.DataPoints.Add(dataPoint)
Next
Dim dataSeries2 As New DataSeries
'单个数据线
dataSeries2.RenderAs = Visifire.Charts.RenderAs.Column
dataSeries2.LegendText = "数据线2"
Dim count2 As Integer = 6
Dim random2 As New Random()
For i As Integer = 0 To count - 1
'单个数据线中的数据点
Dim dataPoint2 As New DataPoint
dataPoint2.YValue = random.Next(1, 100)
dataSeries2.DataPoints.Add(dataPoint2)
Next
chart.Series.Add(dataSeries)
chart.Series.Add(dataSeries2)
Me.LayoutRoot.Children.Add(chart)