Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MSChart:如何更改某些AxisLabel_C#_Charts_Mschart - Fatal编程技术网

C# MSChart:如何更改某些AxisLabel

C# MSChart:如何更改某些AxisLabel,c#,charts,mschart,C#,Charts,Mschart,我想为我的图表更改某些系列中的一些AxisLabels DataTable dt = new DataTable(); SqlCommand s = new SqlCommand("ReportMonthly", SCon); s.CommandType = CommandType.StoredProcedure; s.Parameters.AddWithValue("@Y", Y);

我想为我的图表更改某些系列中的一些AxisLabels

            DataTable dt = new DataTable();
            SqlCommand s = new SqlCommand("ReportMonthly", SCon);
            s.CommandType = CommandType.StoredProcedure;
            s.Parameters.AddWithValue("@Y", Y);
            SCon.Open();
            SqlDataReader dr = s.ExecuteReader();
            dt.Load(dr);            
            chtWRMonthly.DataSource = dt;
            chtWRMonthly.Series["Sold"].XValueMember = "x";            
            chtWRMonthly.Series["sRemaining"].XValueMember = "x";            
            chtWRMonthly.Series["Bought"].XValueMember = "x";            
            chtWRMonthly.Series["bRemaining"].XValueMember = "x";

            chtWRMonthly.Series["Sold"].YValueMembers = "sTAccount";
            chtWRMonthly.Series["sRemaining"].YValueMembers = "sRemaining";
            chtWRMonthly.Series["Bought"].YValueMembers = "bTAccount";
            chtWRMonthly.Series["bRemaining"].YValueMembers = "bRemaining";
            SCon.Close();

            //انتصاب نام ماه ها
            foreach (Series SR in chtWRMonthly.Series)
            {
                foreach (DataPoint DP in SR.Points)
                {
                    switch (DP.AxisLabel)
                    {
                        case "1":
                            DP.AxisLabel = "x1";
                            break;
                        case "2":
                            DP.AxisLabel = "x2";
                            break;
                        case "3":
                            DP.AxisLabel = "x3";
                            break;
                        case "4":
                            DP.AxisLabel = "x4";
                            break;
                  }                        
                }
             }

我试图通过一个开关更改它们,但什么也没发生。

您的
数据点
没有真正的
Axis标签
。它们显示的字符串是从
DataPoint.XValues
自动创建的

所以你的开关永远不会成功

替换

 switch (DP.AxisLabel)

它会起作用的

请注意,我已将
双精度
XValue
转换为
字符串
,以适应您的
开关
代码。如果将
开关
选项更改为
数字
,则可以直接使用它

在设置了
Axis标签之后,您可以将其用于测试,但在此之前不得使用


请参阅各种图表标签的列表。

您能在这里为初学者添加代码吗?
 switch (DP.XValue + "")