Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 具有多个系列的DVC线系列图表_C#_Wpf_Visual Studio_Xaml - Fatal编程技术网

C# 具有多个系列的DVC线系列图表

C# 具有多个系列的DVC线系列图表,c#,wpf,visual-studio,xaml,C#,Wpf,Visual Studio,Xaml,如何使用DVC线系列图添加多个系列 我有以下代码来生成我的第一个系列: WPF: C#: 使用系统; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Threading.Tasks; 使用System.Windows; 使用System.Windows.Controls; 使用System.Windows.Data; 使用System.Windows.Documents; 使用System.Windows.Input

如何使用DVC线系列图添加多个系列

我有以下代码来生成我的第一个系列:

WPF:


C#:

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
使用System.Windows.Controls.DataVisualization;
使用System.Windows.Controls.Primitives;
使用System.Windows.Controls.DataVisualization.Charting;
命名空间WpfApplication1
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
LoadLineChartData();
}
私有void LoadLineChartData()
{
((LineSeries)图表系列[0]).ItemsSource=
新的KeyValuePair[]{
新的KeyValuePair(DateTime.Now,100),
新的KeyValuePair(DateTime.Now.AddMonths(1),130),
新的KeyValuePair(DateTime.Now.AddMonths(2),150),
新的KeyValuePair(DateTime.Now.AddMonths(3),125),
新的KeyValuePair(DateTime.Now.AddMonths(4),155)};
}
}
}
C代码是设置序列的地方,我只需要知道如何添加另一个


提前感谢。

您可以在代码隐藏中完成所有操作。从XAML中删除
部分。 然后,您可以通过编程方式设置所有系列(此示例基于XAML并添加一个系列,复制任意次数(即使用FOR循环)以添加多个系列):

private void LoadLineChartData()
{
//图表是Xaml中的图表对象
//申报你的系列
LineSeries ls=新的LineSeries();
ls.Title=“每月盘点”;
ls.IndependentValueBinding=新绑定(“键”);
ls.DependentValueBinding=新绑定(“值”);
ls.ItemsSource=新的KeyValuePair[]
{
新的KeyValuePair(DateTime.Now,100),
新的KeyValuePair(DateTime.Now.AddMonths(1),130),
新的KeyValuePair(DateTime.Now.AddMonths(2),150),
新的KeyValuePair(DateTime.Now.AddMonths(3),125),
新的KeyValuePair(DateTime.Now.AddMonths(4),155)};
//然后将其添加到图表中
图.系列.添加(ls);
}
}
<DVC:Chart Name="Chart"
           Background="#463F3F">                
        <DVC:Chart.Series>
            <DVC:LineSeries Title=" Monthly Count" IndependentValueBinding="{Binding Path=Key}" DependentValueBinding="{Binding Path=Value}">
        </DVC:LineSeries>
    </DVC:Chart.Series>
    <DVC:Chart.PlotAreaStyle>
        <Style TargetType="Grid">
            <Setter Property="Background" Value="Transparent" />
        </Style>
    </DVC:Chart.PlotAreaStyle>
</DVC:Chart>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Windows.Controls.DataVisualization;
using System.Windows.Controls.Primitives;
using System.Windows.Controls.DataVisualization.Charting;

namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        LoadLineChartData();

    }

    private void LoadLineChartData()
    {
        ((LineSeries)Chart.Series[0]).ItemsSource =
            new KeyValuePair<DateTime, int>[]{
    new KeyValuePair<DateTime,int>(DateTime.Now, 100),
    new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(1), 130),
    new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(2), 150),
    new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(3), 125),
    new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(4),155)};
    }
}
}
private void LoadLineChartData()
{
    //Chart is your chart object in Xaml
    //declare your series
    LineSeries ls = new LineSeries();

    ls.Title = "Monthly Count";
    ls.IndependentValueBinding = new Binding("Key");
    ls.DependentValueBinding = new Binding("Value");

    ls.ItemsSource = new KeyValuePair<DateTime, int>[]
    {
        new KeyValuePair<DateTime,int>(DateTime.Now, 100),
        new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(1), 130),
        new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(2), 150),
        new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(3), 125),
        new KeyValuePair<DateTime,int>(DateTime.Now.AddMonths(4),155)};

        // then add it to the chart
        Chart.Series.Add(ls);    
    }
}