0

我正在尝试按照代码创建条形图,其中条形必须按用户名分组,但不知何故重复问题标签如下所示,

在此处输入图像描述

我的数据表类似于,

Question="Gravimetry"
Project-test1=0
Project-test2=1

Question="Sub-Surface"
Project-test1=0
Project-test2=2

Question="VSP"
Project-test1=2
Project-test2=3
.....

C# 是,

            Series Series = new Series("Series1");
            Chart4.Series.Add("Series1");
            Chart4.Series.Add("Series2");

            Chart4.ChartAreas.Add("ChartArea1");

            // Set series chart type
            Chart4.Series["Series1"].ChartType = SeriesChartType.Bar;
            Chart4.Series["Series2"].ChartType = SeriesChartType.Bar;


            // Set series point width
            Chart4.Series["Series1"]["PointWidth"] = "0.6";
            Chart4.Series["Series2"]["PointWidth"] = "0.6";

            // Show data points labels
            Chart4.Series["Series1"].IsValueShownAsLabel = true;
            Chart4.Series["Series2"].IsValueShownAsLabel = true;

            // Set data points label style
            Chart4.Series["Series1"]["BarLabelStyle"] = "Center";
            Chart4.Series["Series2"]["BarLabelStyle"] = "Center";

            // Draw as 3D Cylinder
            Chart4.Series["Series1"]["DrawingStyle"] = "Cylinder";
            Chart4.Series["Series2"]["DrawingStyle"] = "Cylinder";

            Chart4.DataSource = dt.DefaultView;

            Chart4.ChartAreas["ChartArea1"].AxisX.Interval = 1;

            Chart4.Series["Series1"].XValueMember = "Question";

            //Chart4.Series["Series1"].YValuesPerPoint = 2;

            Chart4.Series["Series1"].YValueMembers = "Project-test1";
            Chart4.Series["Series2"].YValueMembers = "Project-test2";

            Chart4.DataBind();

任何帮助都感激不尽!

4

1 回答 1

0

看一下Chart.DataBindTable 方法;它似乎绑定到表并提供按列分组。例如:

Chart4.DataBindTable(dt, "Question");

应该为表中的每个附加列创建一个系列,按问题列分组。

如果您需要更多自定义,还有Chart.DataBindCrossTable 方法,它允许您指定用于创建系列值的列。

于 2013-04-18T15:59:13.160 回答