charts - Devexpress xtraChart 如何分配x和y值?

标签 charts devexpress

我在数据源中有值,并且数据源没有问题。我必须为图表指定 X 和 Y 值。图表抛出错误并表示不存在名为“TotalInboundArrivals”的列。

ChartControl chart = new ChartControl();
chart.Location = new Point(38, 301);
chart.Size = new Size(789, 168);
Series series = new Series("Series1", ViewType.Bar);
chart.Series.Add(series);
series.DataSource = ds;
series.ArgumentScaleType = ScaleType.Numerical;
series.ArgumentDataMember = "TotalInboundArrivals"; //throws error here
series.ValueScaleType = ScaleType.Numerical;
series.ValueDataMembers.AddRange(new string[] { "StartTime" }); //throws error here 

((SideBySideBarSeriesView)series.View).ColorEach = true;
((XYDiagram)chart.Diagram).AxisY.Visible = true;
chart.Legend.Visible = true;
chart.Visible = true;
chart.Dock = DockStyle.Fill;
xtraTabPage1.Controls.Add(chart);

我的问题出在哪里?有什么建议吗?

最佳答案

你经历过Series.DataSource Property吗? 。您犯了将 DataSet 作为 DataSource 分配给系列的错误。想一想,它怎么能在数据源中搜索列呢?尝试指定 Ds.Tables["TableName"] 作为数据源。

创建数据源表

private DataTable CreateChartData(int rowCount) {
            // Create an empty table.
            DataTable table = new DataTable("Table1");

            // Add two columns to the table.
            table.Columns.Add("Argument", typeof(Int32));
            table.Columns.Add("Value", typeof(Int32));

            // Add data rows to the table.
            Random rnd = new Random();
            DataRow row = null;
            for (int i = 0; i < rowCount; i++) {
                row = table.NewRow();
                row["Argument"] = i;
                row["Value"] = rnd.Next(100);
                table.Rows.Add(row);
            }

指定数据源对应的Series属性

Series series = new Series("Series1", ViewType.Bar);
            chart.Series.Add(series);

            // Generate a data table and bind the series to it.
            series.DataSource = CreateChartData(50);

            // Specify data members to bind the series.
            series.ArgumentScaleType = ScaleType.Numerical;
            series.ArgumentDataMember = "Argument";
            series.ValueScaleType = ScaleType.Numerical;
            series.ValueDataMembers.AddRange(new string[] { "Value" });

检查Examples并浏览创建图表 -> 提供数据部分以更好地理解它。

Reference

希望这有帮助。

关于charts - Devexpress xtraChart 如何分配x和y值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13173139/

相关文章:

javascript - 为什么 Angular ChartJS 中的一个标签上有更多列?

javascript - Chart.js:数据集可以叠加在条形图中吗? (与堆叠不同)

javascript - 使用代码创建 Google 图表

c# - 在 MouseDown 事件处理程序中检测 Ctrl+Left(鼠标按钮)

python - 将日期标签添加到 reportlab LinePlot 图表

c# - 如何在 Visual Studio C# 中制作图表动画?

c# - 如何在运行时运行 Devexpress 报表设计器?

c# - 表单数据集更新

asp.net-mvc-4 - 如何在 Devexpress Control 的富文本编辑器中添加自定义邮件合并字段

javascript - 为什么我不能用 Typescript (Javascript) 替换换行符