文章出處
文章列表
在本篇文章中,我們將闡述如何定制 C1WPFChart 數據點的標記。
下面分步講解實現:
1.定制自定義樣式:
1: <Window.Resources>
2: <Style x:Key="happy" TargetType="{x:Type c1:PlotElement}">
3: <Setter Property="Stroke" Value="Transparent"/>
4: <Setter Property="Fill">
5: <Setter.Value>
6: <ImageBrush>
7: <ImageBrush.ImageSource>
8: <BitmapImage UriSource="pack://application:,,,/Images/happy.jpg"/>
9: </ImageBrush.ImageSource>
10: </ImageBrush>
11: </Setter.Value>
12: </Setter>
13: </Style>
14: </Window.Resources>
2.現在,我們可以指定自定義的 SymbolStyle 到 C1WPFChart 。
3.通過 XAML 加載樣式:
1: <c1:DataSeries Label="Growth" SymbolStyle="{StaticResource happy}" SymbolMarker="Box" SymbolSize="30,30" RenderMode="Default" Values="20 45 19 24 25 5 15 30 12 40" />
4.通過 PlotElementLoaded 事件加載。
1: private void DataSeries_PlotElementLoaded(object sender, EventArgs e)
2: {
3: PlotElement pe = (PlotElement)sender;
4:
5: if (!(pe is Lines)) // skip lines
6: {
7: DataPoint dp = pe.DataPoint;
8: pe.Fill = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Images/happy.jpg")));
9: }
10: }
同時,通過后臺代碼進行不同圖表數據標記的定制:
1: private void DataSeries_PlotElementLoaded(object sender, EventArgs e)
2: {
3: PlotElement pe = (PlotElement)sender;
4:
5: if (!(pe is Lines)) // skip lines
6: {
7: DataPoint dp = pe.DataPoint;
8: pe.Stroke = Brushes.Transparent;
9: if (dp.Value <= 20)
10: {
11: pe.Fill = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Images/sad.jpg")));
12: }
13: else if (dp.Value > 20)
14: {
15: pe.Fill = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Images/happy.jpg")));
16: }
17: }
18: }
效果圖:
Demo 下載:
點擊下載: CS_DEMO
點擊下載: VB.NET_Demo
文章列表
全站熱搜