WPFTookit Chart 高级进阶
数据源增加SeriesSource
使用方式
<Charting:Chart x:Name="chart"
Helper:ChartHelper.DependentValueBinding="Value"
Helper:ChartHelper.IndependentValueBinding="Key"
Helper:ChartHelper.Title="TitlePropertyOnCollection"
Helper:ChartHelper.SeriesType="Line"
Helper:ChartHelper.SeriesSource="{Binding Path=MyCollectionofCollections}" />
增加依赖属性
public enum SeriesType
{
Line,
Bar,
Column,
Scatter,
Pie
}
public class ChartHelper
{
#region SeriesSource public static readonly DependencyProperty SeriesSourceProperty =
DependencyProperty.RegisterAttached("SeriesSource",
typeof(IEnumerable),
typeof(ChartHelper),
new PropertyMetadata(SeriesSourceChanged)); public static IEnumerable GetSeriesSource(DependencyObject d)
{
return (IEnumerable)d.GetValue(SeriesSourceProperty);
} public static void SetSeriesSource(DependencyObject d, IEnumerable value)
{
d.SetValue(SeriesSourceProperty, value);
} #endregion #region DependentValueBinding public static readonly DependencyProperty DependentValueBindingProperty =
DependencyProperty.RegisterAttached("DependentValueBinding",
typeof(string),
typeof(ChartHelper),
null); public static string GetDependentValueBinding(DependencyObject d)
{
return (string)d.GetValue(DependentValueBindingProperty);
} public static void SetDependentValueBinding(DependencyObject d, string value)
{
d.SetValue(DependentValueBindingProperty, value);
} #endregion #region IndependentValueBinding public static readonly DependencyProperty IndependentValueBindingProperty =
DependencyProperty.RegisterAttached("IndependentValueBinding",
typeof(string),
typeof(ChartHelper),
null); public static string GetIndependentValueBinding(DependencyObject d)
{
return (string)d.GetValue(IndependentValueBindingProperty);
} public static void SetIndependentValueBinding(DependencyObject d, string value)
{
d.SetValue(IndependentValueBindingProperty, value);
} #endregion #region Title public static readonly DependencyProperty TitleProperty =
DependencyProperty.RegisterAttached("Title",
typeof(string),
typeof(ChartHelper),
null); public static string GetTitle(DependencyObject d)
{
return (string)d.GetValue(TitleProperty);
} public static void SetTitle(DependencyObject d, string value)
{
d.SetValue(TitleProperty, value);
} #endregion #region SeriesType public static readonly DependencyProperty SeriesTypeProperty =
DependencyProperty.RegisterAttached("SeriesType",
typeof(SeriesType),
typeof(ChartHelper),
new PropertyMetadata(SeriesType.Bar)); public static SeriesType GetSeriesType(DependencyObject d)
{
return (SeriesType)d.GetValue(SeriesTypeProperty);
} public static void SetSeriesType(DependencyObject d, SeriesType value)
{
d.SetValue(SeriesTypeProperty, value);
} #endregion #region SeriesStyle public static readonly DependencyProperty SeriesStyleProperty =
DependencyProperty.RegisterAttached("SeriesStyle",
typeof(Style),
typeof(ChartHelper),
null); public static Style GetSeriesStyle(DependencyObject d)
{
return (Style)d.GetValue(SeriesStyleProperty);
} public static void SetSeriesStyle(DependencyObject d, Style value)
{
d.SetValue(SeriesStyleProperty, value);
} #endregion private static void SeriesSourceChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
if(!(d is Chart))
{
throw new Exception("Series attached property only works on a Chart type");
} var chart = d as Chart; /* Clear out any old series in the chart */
chart.Series.Clear(); /* Get our collection of data we need for each series */
var chartSeriesSource = e.NewValue as IEnumerable; if(chartSeriesSource == null)
throw new Exception("The SeriesSource does not support IEnumerable"); /* Loop over each collection of data */
foreach(var dataSource in chartSeriesSource)
{
DynamicSeries series; /* Find out what type of series we want to use */
var seriesType = GetSeriesType(chart); switch(seriesType)
{
case SeriesType.Line:
series = new LineSeries();
break;
case SeriesType.Bar:
series = new BarSeries();
break;
case SeriesType.Column:
series = new ColumnSeries();
break;
case SeriesType.Pie:
series = new PieSeries();
break;
case SeriesType.Scatter:
series = new ScatterSeries();
break;
default:
throw new ArgumentOutOfRangeException();
} /* Get and set the style of the newly created series */
var seriesStyle = GetSeriesStyle(chart);
series.Style = seriesStyle; string titleBindingName = GetTitle(chart); if (!string.IsNullOrEmpty(titleBindingName))
{
/* Do some binding of the Title property */
var titleBinding = new Binding(titleBindingName)
{
Source = series.Title, Mode = BindingMode.TwoWay
}; series.SetBinding(Series.TitleProperty, titleBinding);
} /* Setup the bindings configured in the attached properties */
series.DependentValueBinding = new Binding(GetDependentValueBinding(chart));
series.IndependentValueBinding = new Binding(GetIndependentValueBinding(chart)); /*Set the ItemsSource property, which gives the data to the series to be rendered */
series.ItemsSource = dataSource as IEnumerable; /* Add the series to the chart */
chart.Series.Add(series);
}
}
}
WPFTookit Chart 高级进阶的更多相关文章
- 潭州学院-JavaVIP的Javascript的高级进阶-KeKe老师
潭州学院-JavaVIP的Javascript的高级进阶-KeKe老师 讲的不错,可以学习 下面是教程的目录截图: 下载地址:http://www.fu83.cn/thread-283-1-1.htm ...
- C#可扩展编程之MEF学习笔记(五):MEF高级进阶
好久没有写博客了,今天抽空继续写MEF系列的文章.有园友提出这种系列的文章要做个目录,看起来方便,所以就抽空做了一个,放到每篇文章的最后. 前面四篇讲了MEF的基础知识,学完了前四篇,MEF中比较常用 ...
- 高级进阶DB2(第2版)——内部结构、高级管理与问题诊断
<高级进阶DB2(第2版)——内部结构.高级管理与问题诊断> 基本信息 作者: 牛新庄 出版社:清华大学出版社 ISBN:9787302323839 上架时间:2013-7-3 出版 ...
- MEF高级进阶
MEF高级进阶 好久没有写博客了,今天抽空继续写MEF系列的文章.有园友提出这种系列的文章要做个目录,看起来方便,所以就抽空做了一个,放到每篇文章的最后. 前面四篇讲了MEF的基础知识,学完了前四 ...
- .Net高级进阶,在复杂的业务逻辑下,如何以最简练的代码,最直观的编写事务代码?
本文将通过场景例子演示,来通俗易懂的讲解在复杂的业务逻辑下,如何以最简练的代码,最直观的编写事务代码. 通过一系列优化最终达到两个效果,1.通过代码块来控制事务(分布式事务),2.通过委托优化Tran ...
- 《Android高级进阶》读书笔记
<Android高级进阶>是据我所知的市面上唯一一本技术工具书,比较的高大全,作者的目的是为了对全领域有个初步的概念 No1: 在Android系统中,拥有事件传递处理能力的类有以下三种 ...
- Git log diff config高级进阶
Git 历史相关和 git config 高级进阶 前一段时间分享了一篇<更好的 git log>简要介绍怎么美化 git log 命令,其中提到了 alias命令,今天再继续谈谈 git ...
- [总]Android高级进阶之路
个人Android高级进阶之路,目前按照这个目录执行,执行完毕再做扩展!!!!! 一.View的绘制 1)setContentView()的源码分析 2)SnackBar的源码分析 3)利用decor ...
- 高级进阶DB2(第2版)
<高级进阶DB2(第2版)> 基本信息 作者: 牛新庄 出版社:清华大学出版社 ISBN:9787302323839 上架时间:2013-7-3 出版日期:2013 年7月 开本:16开 ...
随机推荐
- AutoMapper 使用实践
一. 使用意图 常常在开发过程中,碰到一个实体上的属性值,要赋值给另外一个相类似实体属性时,且属性有很多的情况.一般不利用工具的话,就要实例化被赋值实体B,然后再将实体A的字段一个个赋值给B的属性 ...
- 用Kotlin改写PHP程序是什么样的体验
学Kotlin其实要看:http://kotlinlang.org/docs/kotlin-docs.pdf 在线版是不完整的!!!少了一些章节,会有点难看懂后面的文档. 我选择了WordPress里 ...
- 数据结构:链表(python版) 续:增加比较函数
题目: 基于元素相等操作"=="定义一个单链表的相等比较函数.另请基于字典序的概念,为链表定义大于,小于,大于等于,小于等于的判断 class LList: "" ...
- java servlet 几种页面跳转的方法及传值
java servlet 几种页面跳转的方法及传值 java web 页面之间传值有一下这几种方式1.form 表单传递参数2.url地址栏传递参数3.session4.cookie5.appli ...
- ABP中使用OAuth2(Resource Owner Password Credentials Grant模式)
ABP目前的认证方式有两种,一种是基于Cookie的登录认证,一种是基于token的登录认证.使用Cookie的认证方式一般在PC端用得比较多,使用token的认证方式一般在移动端用得比较多.ABP自 ...
- 000.Introduction to ASP.NET Core--【Asp.net core 介绍】
Introduction to ASP.NET Core Asp.net core 介绍 270 of 282 people found this helpful By Daniel Roth, Ri ...
- [ASP.NET MVC] ASP.NET Identity登入技术应用
[ASP.NET MVC] ASP.NET Identity登入技术应用 情景 ASP.NET Identity是微软所贡献的开源项目,用来提供ASP.NET的验证.授权等等机制.在ASP.NET I ...
- 使用HBaseShellPro操作Hadoop 2系列发行版CDH4.4
前言 对于hadoop,hbase由于项目紧张原因好几个月没有时间认真的来总结下了,最近有一些空,就来继续的把项目中用到的一些技术实际的写出来,动动手,好久没有写东西了,都生疏了,说起hadoop,公 ...
- link与@import的区别
我们都知道link与@import都可以引入css样式表,那么这两种的区别是什么呢?先说说它们各自的链接方式,然后说说它们的区别~~~ link链入的方式: <link rel="st ...
- CSS中详解hight属性
目录结构: // contents structure [-] hight属性值类型一览表 height的%的使用 定义 实例 需要注意的 参考文章 hight属性值类型一览表 value descr ...