因爲項目中常常用到Series Chart,而目前市面又實在找不到既支持MVVM,又輕量級的開源Chart控件,因而乾脆就花了兩週時間隨手寫了一個。昨天感受還比較滿意,就發佈到了Github上:https://github.com/zenjia/MvvmChartgit
Line Series,無Item Point:(從上自下依次爲PolylineSeries、StepLineSeries、SplineSeries)github
Line Series,帶Item Point:設計模式
Area Series,不帶Item Point:mvvm
Area Series,帶Item Point:ui
首先定義數據點:spa
public class SomePoint { public double t { get; } public double Y { get; } } public class DemoDataViewModel { public List<List<SomePoint>> ItemsSourceList { get; } }
而後建立DataTemplate:設計
<DataTemplate x:Key="SeriesTemplate1"> <mvvmCharting:PolyLineSeries IndependentValueProperty="t" DependentValueProperty="Y" Stroke="Red" StrokeThickness="1.5" ItemsSource="{Binding}"> </mvvmCharting:PolyLineSeries> </DataTemplate>
最後,建立一個SeriesChart,並引用上面的DateTemplate:code
<mvvmCharting:SeriesChart Background="Bisque" SeriesDataTemplate="{StaticResource SeriesTemplate1}" SeriesItemsSource="{Binding ItemsSourceList, Source={StaticResource GlobalDemoDataViewModel}}"> <mvvmCharting:SeriesChart.XAxis> <axis:XAxis /> </mvvmCharting:SeriesChart.XAxis> <mvvmCharting:SeriesChart.YAxis> <axis:YAxis /> </mvvmCharting:SeriesChart.YAxis> </mvvmCharting:SeriesChart>
(更多使用Sample見項目裏的Demo工程)blog
(對UWP的支持將很快加入)繼承
(歡迎批評指正,歡迎提交bug)