如何将数据绑定到windows store app中的barchart(WInRt XAML工具包) [英] how to bind data to barchart(WInRt XAML toolkit) in windows store app

查看:78
本文介绍了如何将数据绑定到windows store app中的barchart(WInRt XAML工具包)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务中获取数据,我正在尝试将数据绑定到条形图我无法做到这一点看到我的代码

I am fetching data from service and I am trying to bind data to bar chart I am unable to do this see my code

protected async override void OnNavigatedTo(NavigationEventArgs e) 
{
       StatusServiceReferenceHost.Service1Client MyService = new StatusServiceReferenceHost.Service1Client();
       var data = await MyService.GetStatusAsync();

       foreach (var cchart in cidata)
       {
           //I am nt sure how to bind
           (dataChart.Series[0] as BarSeries).ItemsSource = cdata;
       }


我的get方法中的
我有更多列,但我想只绑定2列,假设我有名字和datacount列请帮助我这个


in my get method I have more columns but I wanto bind only 2 columns suppose I have name and datacount columns pls help me onthis

推荐答案

你好jayantik,

你必须动态地向每个系列添加数据。我认为下面的代码是你的解决方案(代码在vb.net中)。如果你需要更多帮助,请回复我。



hello jayantik ,
you have to dynamically add data to every series.I think below code is your solution(code is in vb.net).reply me if u need more help.

If (dt.Rows.Count > 0) Then

                YourChart.DataSource = dt

                YourChart.Series.Clear()

                For colIndex As Integer = 1 To dt.Columns.Count - 1
                    ' For each column (column 1 and onward) add the value as a point
                    Dim Cseries As New Series(dt.Columns(colIndex).ColumnName)
                    Cseries.Points.Clear()
                    For Each dr In dt.Rows
                        Dim tempi As Integer = Convert.ToInt32(IIf(IsDBNull(dr(colIndex)), 0, dr(colIndex)))
                        Cseries.Points.AddXY(dr("Code"), tempi)
                    Next
                    YourChart.Series.Add(Cseries)
                    ' YourChart.Series(dt.Columns(colIndex).ColumnName)("PointWidth") = "2"
                    YourChart.Series(dt.Columns(colIndex).ColumnName).IsValueShownAsLabel = True

                    YourChart.Series(dt.Columns(colIndex).ColumnName).IsVisibleInLegend = True
                    YourChart.Series(dt.Columns(colIndex).ColumnName).Color = LegendColor(dt.Columns(colIndex).ColumnName)
                Next
                YourChart.DataBind()
                YourChart.Titles.Clear()
                ' YourChart.AlternateText.SmartLabel.DynamicDisplay = False
                YourChart.ChartAreas(0).AxisX.Interval = 1
                YourChart.ChartAreas(0).AxisX.Title = "Locations"
                YourChart.ChartAreas(0).AxisY.Title = "Numbers"
                shiftSelectedDate = DateTime.Now
                YourChart.Titles.Add("Summary")
                YourChart.Titles.Add("Record for the date:-" + " " + shiftSelectedDate.ToString("dd-MMM-yy"))

            Else
                YourChart.Titles.Clear()
                'YourChart.Series(0).Points.Clear()
                shiftSelectedDate = DateTime.Now
                YourChart.AlternateText = ""
                ' YourChart.Titles.Add("Summary")
                YourChart.Titles.Add("No Record for the date:-" + " " + shiftSelectedDate.ToString("dd-MMM-yy"))
            End If





Aditya Prakash

软件工程师

种子管理服务pvt ltd



Aditya Prakash
Software Enginner
Seed Management Services pvt ltd


这里我的代码在c#...我认为这段代码可以帮到你..

here i my code in c#...i think this code can help you..
if ((dt.Rows.Count > 0)) {

    YourChart.DataSource = dt;

    YourChart.Series.Clear();

    for (int colIndex = 1; colIndex <= dt.Columns.Count - 1; colIndex++) {
        // For each column (column 1 and onward) add the value as a point
        Series Cseries = new Series(dt.Columns(colIndex).ColumnName);
        Cseries.Points.Clear();
        foreach (void dr_loopVariable in dt.Rows) {
            dr = dr_loopVariable;
            int tempi = Convert.ToInt32((Information.IsDBNull(dr(colIndex)) ? 0 : dr(colIndex)));
            Cseries.Points.AddXY(dr("Code"), tempi);
        }
        YourChart.Series.Add(Cseries);
        // YourChart.Series(dt.Columns(colIndex).ColumnName)("PointWidth") = "2"
        YourChart.Series(dt.Columns(colIndex).ColumnName).IsValueShownAsLabel = true;

        YourChart.Series(dt.Columns(colIndex).ColumnName).IsVisibleInLegend = true;
        YourChart.Series(dt.Columns(colIndex).ColumnName).Color = LegendColor(dt.Columns(colIndex).ColumnName);
    }
    YourChart.DataBind();
    YourChart.Titles.Clear();
    // YourChart.AlternateText.SmartLabel.DynamicDisplay = False
    YourChart.ChartAreas(0).AxisX.Interval = 1;
    YourChart.ChartAreas(0).AxisX.Title = "Locations";
    YourChart.ChartAreas(0).AxisY.Title = "Numbers";
    shiftSelectedDate = DateTime.Now;
    YourChart.Titles.Add("Summary");
    YourChart.Titles.Add("Record for the date:-" + " " + shiftSelectedDate.ToString("dd-MMM-yy"));

} else {
    YourChart.Titles.Clear();
    //YourChart.Series(0).Points.Clear()
    shiftSelectedDate = DateTime.Now;
    YourChart.AlternateText = "";
    // YourChart.Titles.Add("Summary")
    YourChart.Titles.Add("No Record for the date:-" + " " + shiftSelectedDate.ToString("dd-MMM-yy"));
}


这篇关于如何将数据绑定到windows store app中的barchart(WInRt XAML工具包)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆