ASP.NET图表控件 - 如何创建此条形图? [英] ASP.NET chart controls - how do i create this bar chart?

查看:255
本文介绍了ASP.NET图表控件 - 如何创建此条形图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个图表控件,我想从一个数据表。

Got a chart control i wanna make from a data table.

表格如下:

我想要的图表将如下所示:

the chart i want will look like this:

''' 
''''
'''''       '' '  
'''''       '' '
ECCTMP      ECCTMP       ECCTMP   
Monday      Tuesday      Wednesday

希望这对每天的分组有意义

hope this makes sense for each day its grouped b y the type (email, calls).

我只是现在确定如何将其数据绑定?

I'm just now sure how to databind it?

推荐答案

如果您要在条形图中分组系列,那么您需要使用 Chart.DataBindTable 方法(MSDN)

If you're looking to group series in a bar chart then you'll need to use the Chart.DataBindTable method (MSDN).

只需添加以下代码:

Chart1.DataBindTable(IEtable, "Day");

这将产生一个类似如下的图表:

This will produce a chart that looks something like the following:

以下是一些用于测试的虚拟代码:

Here's some dummy code to use as a test:

DataTable table = new DataTable();
table.Columns.Add("Day", typeof(string));
table.Columns.Add("Email", typeof(int));
table.Columns.Add("Calls", typeof(int));
table.Columns.Add("Contacts", typeof(int));
table.Columns.Add("Tasks", typeof(int));
table.Columns.Add("Meetings", typeof(int));
table.Columns.Add("Proposals", typeof(int));

table.Rows.Add("Monday", 1, 3, 3, 4, 5, 5);
table.Rows.Add("Tuesday", 1,6,8,2,0,3);
table.Rows.Add("Wednesday", 7, 6,3,0,2,1);
table.Rows.Add("Thursday", 1,5,5,9,3,1);
table.Rows.Add("Friday", 4,7,3,5,2,3);

//convert datatable to a IEnumerable form
var IEtable = (table as System.ComponentModel.IListSource).GetList();

//Bind the datatable to the chart using the DataBindTable method
Chart1.DataBindTable(IEtable, "Day");

也可以使用ECCTMP描述的标签,但添加图例清洁剂。

It is also possible to have the labels appear as you describe with ECCTMP but adding a legend will probably look cleaner.

这篇关于ASP.NET图表控件 - 如何创建此条形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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