当前位置:   article > 正文

可用于wpf的图表控件:WPFTookit Chart

wpf mschart datavisualization

  当前项目需要一个图表控件,尝试用过mschart和livechart,都不是很满意。这里试一下WPFToolkit.DataVisualization。

  1. 引用dll,通过nuget包管理器下载WPFToolkit.DataVisualization和WPFToolkit(前者依赖于后者,两个都要安装)
  2. xaml代码:
    <Window x:Class="ChartTestInWPF.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:ChartTestInWPF"
       xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800">
        <Grid>
            <charting:Chart  Height="271" Name="chart1" Width="379">
                <charting:Chart.Series>
                    <charting:PieSeries ItemsSource="{Binding}"
                        DependentValuePath="Value"
                        IndependentValuePath="Key"
                        Title="Pet Preference" IsSelectionEnabled="True" />
                </charting:Chart.Series>
            </charting:Chart>
        </Grid>
    </Window>

    cs文件代码:

    1. chart1.DataContext = new KeyValuePair<string, int>[] {
    2. new KeyValuePair<string, int>("Dog", 30),
    3. new KeyValuePair<string, int>("Cat", 25),
    4. new KeyValuePair<string, int>("Rat", 5),
    5. new KeyValuePair<string, int>("Hampster", 8),
    6. new KeyValuePair<string, int>("Rabbit", 12) };

     运行效果:

  3. 上面说明调用控件成功了,但是我是要绘制一个线性图,并且是动态显示数据的,这里采用了MVVM模式。效果如下
  4.  

  5. 代码上传到微云了:下载地址:https://share.weiyun.com/5TVMsJt
  6. 参考了以下网页:https://www.cnblogs.com/HQFZ/p/4446727.htmlhttp://www.it1352.com/437797.html

转载于:https://www.cnblogs.com/xloveheineken/p/9984033.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/270751
推荐阅读
相关标签
  

闽ICP备14008679号