Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.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# 使用2个系列更改X轴标签的位置_C#_Charts_Mschart_Series - Fatal编程技术网

C# 使用2个系列更改X轴标签的位置

C# 使用2个系列更改X轴标签的位置,c#,charts,mschart,series,C#,Charts,Mschart,Series,我有列类型为2系列的图表: -一个男性系列。 -一个女性系列。 一切都很好,但我正在尝试在X轴底部设置X1、X2标签: 我想把[Units 3333和Units 0099]和[Units 1111和Units 555]放在底部 可能吗 以下是代码cs文件: using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Drawing; using System.Linq; usi

我有列类型为2系列的图表: -一个男性系列。 -一个女性系列。 一切都很好,但我正在尝试在X轴底部设置X1、X2标签:

我想把[Units 3333和Units 0099]和[Units 1111和Units 555]放在底部

可能吗

以下是代码cs文件:

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;

namespace PCMD.AssignTransferSystem.web.Managers
{
    public partial class ColumnChart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.IsClustered = true;
            Chart1.ChartAreas["ChartArea1"].AxisX.IsLabelAutoFit = false;
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.PointDepth = 20;
            Chart1.ChartAreas["ChartArea1"].Area3DStyle.Perspective = 0;
            SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=AssignTransferDB;Integrated Security=True");
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;


        string cmdstr = "select * from ReqUnitsByGender"; // View in DB
        cmd.CommandText = cmdstr;
        SqlDataReader Dr = cmd.ExecuteReader();

        Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
        Chart1.ChartAreas["ChartArea1"].AxisX2.Interval = 1;
        //Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("Arial", 16);
        //Chart1.ChartAreas["ChartArea1"].AxisX2.LabelStyle.Font = new Font("Arial", 16);
        //Chart1.Series["male"].IsValueShownAsLabel = true;
        //Chart1.Series["female"].IsValueShownAsLabel = true;
        //Chart1.Series["male"]["LabelStyle"] = "Bottom";
        //Chart1.Series["female"]["LabelStyle"] = "Bottom";
        //Chart1.Series["male"]["BarLabelStyle"] = "Bottom";
        //Chart1.Series["female"]["BarLabelStyle"] = "Bottom";
        while (Dr.Read())
        {
            if (Dr["Gender"].ToString()=="True")
            {
                Chart1.Series["male"].Points.AddXY(Dr["UnitName"].ToString(), Dr["CountRequest"].ToString());
                Chart1.Series["male"].XAxisType = AxisType.Primary;
            }
            if (Dr["Gender"].ToString() == "False")
            {
                Chart1.Series["female"].Points.AddXY(Dr["UnitName"].ToString(), Dr["CountRequest"].ToString());
                Chart1.Series["female"].XAxisType = AxisType.Secondary;            
            }  
        }
        conn.Close();
    }
}
}

您正在为女性系列使用辅助x轴。换成

Chart1.Series["female"].XAxisType = AxisType.Primary;

你应该准备好了。但是,如果两个系列的x值不相同,则条形图之间可能会有空格。

发布您设置图表的代码。您可以在回答部分bro@mmathisThank中看到我的代码。但是,您的代码不是答案,因此请编辑您的问题并将代码发布在那里,然后删除包含代码的答案。我将一个系列[]主系列另一个是次系列<对于每个系列显示,即使系列有一个值>,例如,如果我将两个系列都放在主系列中:系列[female]在第一个标签上覆盖我不太确定你在描述什么…你能发布一个你想让情节看起来像什么的模型吗?您可以尝试处理次x轴的AxisCrossing属性,但可能会得到重叠的标签。通常,主x轴位于绘图的底部,次x轴位于顶部,这些轴也是相关标签所在的位置。如果希望标签位于底部,则应使用主轴。