无法绑定到数据表图表控件 [英] Can't bind datatable to Chart Control

查看:142
本文介绍了无法绑定到数据表图表控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用极坐标图在我的测试应用程序。我有一个数据表与一对夫妇,其中以X的名称的列应该提供的x值的成员列,其他人应该是y值的成员。我发现在MSDN上的教程,但它并没有真正的工作,因为该行

I'd like to use a polar chart in my test application. I've a data table with a couple of columns where the column with the name of "X" should provide the x value members, the others should be the y value members. I found a tutorial on MSDN but it doesn't really work because the line

chart1.DataBindTable(dt, "X");



将无法编译。 。任何提示,欢迎并感谢您

won't compile. Any tip is welcome and thank you.

下面是代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace PolarChartTest_01
{
    public partial class Form1 : Form
    {
    public DataTable dt;
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        dt.Rows.Clear();
        dt.Columns.Clear();
        chart1.Series.Clear();

        dt.Columns.Add("X", typeof(int));
        dt.Columns.Add("Y", typeof(int));

        for (int j = 0; j < 7; j++)
        {
            DataRow dr = dt.NewRow();

            dr["X"] = j * 45;
            dr["Y"] = j;
            dt.Rows.Add(dr);

        }

        chart1.DataBindTable(dt, "X");
    }
}



}

}

推荐答案

这不能编译,因为DataTable不实现IEnumerable接口。
尝试:

It won't compile because DataTable doesn't implement IEnumerable interface. Try:

var enumerableTable = (dt as System.ComponentModel.IListSource).GetList();
chart1.DataBindTable(enumerableTable , "X");

这篇关于无法绑定到数据表图表控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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