WPF Toolkit Chart--动态换列

效果:


<Window x:Class="切换显示曲线.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:tk="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" Loaded="Window_Loaded">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">选择Series1列:</TextBlock>
<ComboBox x:Name="cmbLine" SelectionChanged="cmbLine_SelectionChanged" SelectedValuePath="Name" Grid.Column="1"></ComboBox>
<TextBlock Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Center">选择Series2列:</TextBlock>
<ComboBox x:Name="cmbLine1" SelectionChanged="cmbLin1_SelectionChanged" SelectedValuePath="Name" Grid.Column="3"></ComboBox>
<tk:Chart Name="chart1" Grid.Row="1" Grid.ColumnSpan="4" >
<tk:Chart.Axes>
<tk:LinearAxis Orientation="X" Interval="1"></tk:LinearAxis>
</tk:Chart.Axes>
<tk:LineSeries x:Name="line1" IndependentValuePath="X" DependentValuePath="Y1" ItemsSource="{Binding}">
<tk:LineSeries.DependentRangeAxis>
<tk:LinearAxis Orientation="Y" Title="{Binding SelectedValue,ElementName=cmbLine}" Interval="1" ></tk:LinearAxis>
</tk:LineSeries.DependentRangeAxis>
</tk:LineSeries>
<tk:LineSeries x:Name="line2" IndependentValuePath="X" DependentValuePath="Y1" ItemsSource="{Binding}" >
<tk:LineSeries.DependentRangeAxis>
<tk:LinearAxis Orientation="Y" Title="{Binding SelectedValue,ElementName=cmbLine1}" Interval="1"></tk:LinearAxis>
</tk:LineSeries.DependentRangeAxis>
</tk:LineSeries>
</tk:Chart>
</Grid>
</Window>

读取一个类的所有属性:

PropertyInfo[] strs = new XYS().GetType().GetProperties();

常用属性


 PropertyInfo prop = strs[0];
string str = prop.Name;//属性名
bool bl = prop.CanRead;//是否可读
bool bl1 = prop.CanWrite;//是否可写
string str1 = prop.PropertyType.Name;//数据类型
bool bl2 = prop.PropertyType.IsArray;//是否为数组
bool bl3 = prop.PropertyType.IsEnum;//是否是枚举

后台代码:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.Windows.Controls.DataVisualization.Charting;

namespace 切换显示曲线
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
{
List<XYS> list = new List<XYS>();
list.Add(new XYS(1, 1, 3, 5, 7));
list.Add(new XYS(2, 2, 4, 6, 8));
list.Add(new XYS(3, 3, 6, 9, 12));
list.Add(new XYS(4, 4, 8, 12,16));

this.DataContext = list;

PropertyInfo[] strs = new XYS().GetType().GetProperties();

//foreach (PropertyInfo pi in strs)
//{
// MessageBox.Show(pi.Name);
//}

cmbLine.ItemsSource = strs;
cmbLine.DisplayMemberPath = "Name";
//cmbLine.SelectedIndex = 1;

cmbLine1.ItemsSource = strs;
cmbLine1.DisplayMemberPath = "Name";
//cmbLin1.SelectedIndex = 2;
}

private void cmbLine_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PropertyInfo pi = cmbLine.SelectedItem as PropertyInfo;
line1.DependentValuePath = pi.Name;
//LinearAxis la = new LinearAxis();
//la.Orientation = AxisOrientation.Y;
//la.Title = pi.Name;
//line1.DependentRangeAxis = la;
}

private void cmbLin1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PropertyInfo pi = cmbLine1.SelectedItem as PropertyInfo;
line2.DependentValuePath = pi.Name;

//LinearAxis la = new LinearAxis();
//la.Orientation = AxisOrientation.Y;
//la.Title = pi.Name;
//line2.DependentRangeAxis = la;

}
}

class XYS
{
public int X { get; set; }
public int Y1 { get; set; }
public int Y2 { get; set; }
public int Y3 { get; set; }
public int Y4 { get; set; }

public XYS(int x,int y1,int y2,int y3,int y4)
{
X = x;
Y1 = y1;
Y2 = y2;
Y3 = y3;
Y4 = y4;
}

public XYS()
{
;
}
}
}

WPF Toolkit Chart--动态换列

时间: 2024-10-04 21:35:01

WPF Toolkit Chart--动态换列的相关文章

WPF Toolkit Chart--多Y轴显示

效果: <Window x:Class="Chart.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width=&quo

WPF Toolkit Chart

<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:toolkit="clr-namespace:System.Windows.Control

WPF ToolKit Chart 自定义样式

1.引用:WPFToolkit.dll, System.Windows.Controls.DataVisualization.Toolkit.dll 2. 页面代码参考如下: <UserControl x:Class="GDNXFD.Alert.IFIXControls.StationPieChart" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="

WPF Datagrid 动态生成列 并绑定数据

原文:WPF Datagrid 动态生成列 并绑定数据 说的是这里 因为列头是动态加载的 (后台for循环 一会能看到代码) 数据来源于左侧列 左侧列数据源 当然num1 属于临时的dome使用  可以用ObservableCollection集合代表 动态创建属性 WPF 动态生成对象属性 (dynamic) ObservableCollection<NameList> listName = new ObservableCollection<NameList>(); privat

WPF DataGrid动态生成列的单元格背景色绑定

原文:WPF DataGrid动态生成列的单元格背景色绑定 <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Column.DisplayIndex}" Value="1"> <Setter Property="Background" Value="{Binding RelativeSource={RelativeSour

WPF datagrid 动态增加列

DataGrid动态增加列 <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="

WPF Toolkit AutoCompleteBox 实体类绑定 关键字自定义关联搜索匹配

原文:WPF Toolkit AutoCompleteBox 实体类绑定 关键字自定义关联搜索匹配 网上的例子都是零散的   翻阅了 很多篇文章后 再根据 自己项目的实际需求  整理出一个完整的 应用例子 汉字首字母全文匹配 提取绑定实体类相应的ID值 XAML <Window x:Class="WpfApp3.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quo

Android动态换肤开源库Colorful发布

最近本人需要用到夜间模式,但是经过一番搜索似乎并没有看到好的开源实现,看到有一个类似的库MultipleTheme,但是需要自定义所有要实现换肤功能的View,感觉比较麻烦.当发现现有的解决方案不能很好的解决问题时,往往只能自己实现,因此本人花了点时间简单弄了一个实现该功能的开源库,命名为Colorful. Colorful是基于Theme,无需重启Activity.无需自定义View,方便的实现日间.夜间模式,github地址为 https://github.com/bboyfeiyu/Col

安装Extended WPF Toolkit

Extended WPF Toolkit 可以说是WPF Toolkit 的一个补充,也包含了许多WPF 控件供开发者使用.本篇将介绍Extended WPF Toolkit 1.4.0 中新增的一些控件. 安装Extended WPF Toolkit Extended WPF Toolkit 安装其实很简单,利用nuget 可以快速将控件库添加到项目中.右键References 选择“Add Library Package Reference...” 在搜索框中输入"Extended WPF