首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有多个系列的DVC折线图

具有多个系列的DVC折线图
EN

Stack Overflow用户
提问于 2013-04-29 21:39:14
回答 1查看 1.3K关注 0票数 0

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

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

WPF:

代码语言:javascript
复制
<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>

C#:

代码语言:javascript
复制
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)};
    }
}
}

C#代码是设置系列的地方,我只需要知道如何添加另一个。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-04-29 22:18:59

你可以在后台代码中做任何事情。从您的XAML中删除<DVC:Chart.Series>部分。然后,您可以通过编程方式设置所有系列(此示例基于您的XAML并添加一个系列,想复制多少次就复制多少次(即使用FOR循环)以添加多个系列):

代码语言:javascript
复制
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);    
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16280122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档