zoukankan      html  css  js  c++  java
  • Studio for WPF:定制 C1WPFChart 标记

    在本篇文章中,我们将阐述如何定制 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

  • 相关阅读:
    自己修改的两个js文件
    .net4缓存笔记
    使用.net的Cache框架快速实现Cache操作
    关于招聘面试(转)
    PHP中获取当前页面的完整URL
    Linux在本地使用yum安装软件(转)
    Phalcon的学习篇-phalcon和devtools的安装和设置
    GY的实验室
    aip接口中对url参数md5加密防篡改的原理
    nginx 多站点配置方法集合(转)
  • 原文地址:https://www.cnblogs.com/C1SupportTeam/p/StudioforWPF_C1WPFChart_SymbolStyle.html
Copyright © 2011-2022 走看看