我正在尝试生成一个图表来查看这个
我快到了,但有几个问题我无法解决。显示的列之间没有空格分隔!最底部的自定义标签也没有与每一列对齐!
这是我从现有代码中得到的输出
所以 1)我需要将列分布在 x 轴上 2)将自定义标签与每一列对齐!
感谢您对此问题的任何帮助或反馈
这是生成当前图像的代码。请记住我的数据集“ds”有这样的值
新兴 28.45646456 凹痕 14.1456465 音频 27.456456 化妆品 43.44564456 兽医 35.15465646645
公共无效生成图表(){
//ds is generated and has values
Chart2.Series.Clear();
Chart2.Legends.Clear();
Chart2.Titles.Clear();
//if (ConfigurationManager.AppSettings["RunOnLocalhost"] == "True") {
if(HttpContext.Current.Request.Url.Host.ToLower() == "localhost"){
Chart2.ImageStorageMode = ImageStorageMode.UseImageLocation;
}
Chart2.Width = 1000;
Chart2.Height = 700;
Chart2.BorderlineDashStyle = ChartDashStyle.Solid;
Chart2.Titles.Add("Usage Impact By Industry");
Chart2.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.LightGray;
Chart2.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.LightGray;
Chart2.ChartAreas[0].AxisX.Interval = 1;
Chart2.ChartAreas[0].AxisY.Interval = 5;
Chart2.ChartAreas[0].AxisX.LabelStyle.Angle = -45;
Chart2.ChartAreas[0].AxisY.Title = "(%) Usage Lift";
Chart2.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 16, FontStyle.Bold);
Chart2.ChartAreas[0].AxisY.Minimum = -5;
string tmp = "";
string sName = "";
double percentage = 0;
int i = 1;
int x = 1;
double index = 0.1;
foreach (DataRow Row in ds.Tables[0].Rows) {
if (tmp != Row["Industry"].ToString()) {
sName = Row["Industry"].ToString();
Chart2.Series.Add(sName);
Chart2.Legends.Add(sName).DockedToChartArea = "ChartArea1";
i++;
}
if (Convert.ToDouble(Row["B4"]) > 0) {
percentage = (Convert.ToDouble(Row["After4"]) - Convert.ToDouble(Row["B4"])) / Convert.ToDouble(Row["B4"]) * 100;
percentage = Math.Round(percentage, 0);
}
else {
percentage = 0;
}
Chart2.Series[sName].Points.AddXY(Row["Industry"].ToString(), percentage);
Chart2.Series[sName].ChartType = SeriesChartType.Column;
Chart2.Series[sName]["PointWidth"] = ".5";
Chart2.Series[sName].IsValueShownAsLabel = true;
Chart2.Series[sName].LabelFormat = percentage + "%";
CustomLabel label = new CustomLabel();
label.FromPosition = 0 + index;
label.ToPosition = .01 + index;
label.Text = Row["Industry"].ToString();
label.RowIndex = 0;
Chart2.ChartAreas[0].AxisX.CustomLabels.Add(label);
x++;
index += 0.2;
tmp = Row["Industry"].ToString();
}
}