我的图表有列类型(2系列):
- 男性的一个系列
- 女性的一个系列
一切都很好,但我试图在底部设置X1,X2标签(在X轴上):
我想将[单元#3333和单元#0099]放在底部[单元#1111和单元#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();
}
}
}
答案 0 :(得分:0)
您正在使用辅助x轴为您的"女性"系列。将其更改为
Chart1.Series["female"].XAxisType = AxisType.Primary;
你应该全力以赴。但是,如果两个系列没有相同的x值,则它们之间可能会有空格。