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开 ...
随机推荐
- Devexpress RaisePropertyChanged
所有的重载设置字段作为参数传递到指定的值,而属性提高INotifyPropertyChanged.PropertyChanged事件. 如果一个字段已经成功地改变,setProperty方法中返回真. ...
- 用c#开发微信(5)自定义菜单设置工具 (在线创建)
读目录 1 使用 2 原理 3. 错误 上次写了<用c#开发微信 (4) 基于Senparc.Weixin框架的接收事件推送处理 (源码下载)>,有园友问到如何创建菜单的问题,今天就介绍下 ...
- TableLayoutPanel导致的闪屏问题
界面Load的时候添加对tableLayoutPanel的处理即可,还可设置窗体的DoubleBuffered属性为True tableLayoutPanel1.GetType().GetProper ...
- luogg_java学习_13_GUI
本文为博主辛苦总结,希望自己以后返回来看的时候理解更深刻,也希望可以起到帮助初学者的作用. 转载请注明 出自 : luogg的博客园 谢谢配合! GUI 容器 JFrame , JPanel , JS ...
- 关于前期在云服务器上部署TOMCAT服务器的问题
如果你要将你的项目放在服务器上(针对云服务器),首先你必须要学会前期部署Tomcat的准备, 第一步:安装jdk,配置环境变量 这个比较简单,配置java环境变量最为简单的方法是将java的 (../ ...
- TensorFlow知识总结
学习资料: 英文官方网站 Tensorflow 将要写的博客目录: 1.使用Spring AOP对异常进行统一处理 2.动态代理模式理解 aop中的动态代理模式 3.工厂模式三种的理解.logger ...
- JdbcTemplate进行查询
1.jdbcTemplate.queryForInt() 和 jdbcTemplate.queryForLong() 例如:下面使用queryForInt()方法传回user表中的记录数: jdbcT ...
- Atitit利用反射获取子类 集合 以及继承树
Atitit利用反射获取子类 集合 以及继承树 想从父类往下找子类的确是不可能的,要知道只要类不是final的话谁都有继承它的自由不需要事前通知父类. Eclipse实现不是重父类开始找而是重子类往回 ...
- 第三十章 elk(1) - 第一种架构(最简架构)
软件版本: es:2.4.0 logstash:2.4.0 kibana:4.6.1 一.logstash安装(收集.过滤日志.构建索引) 1.下载:https://www.elastic.co/do ...
- 浅谈tornado项目应用设计
一.预备知识 最近开始尝试做一些tornado商城项目,在开始之前需要引入一些项目设计知识,如接口,抽象方法抽象类,组合,程序设计原则等,个人理解项目的合理设计可增加其灵活性,降低数据之间的耦合性,提 ...