繁体   English   中英

用2系列更改X轴标签的位置

[英]change the position of X axis Labels with 2 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;
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值不同,则两个小节之间可能会有间距。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM