【发布时间】:2014-10-02 10:07:43
【问题描述】:
我有列类型的图表(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();
}
}
}
【问题讨论】:
-
发布您如何设置图表的代码。
-
你可以在答案部分看到我的代码@mmathis
-
谢谢。但是,您的代码不是答案,因此请编辑您的问题并将代码发布到那里,然后删除包含您的代码的答案。