0

我正在尝试生成一个图表来查看这个 在此处输入图像描述

我快到了,但有几个问题我无法解决。显示的列之间没有空格分隔!最底部的自定义标签也没有与每一列对齐!

这是我从现有代码中得到的输出

在此处输入图像描述

所以 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();
  }



}
4

1 回答 1

0

我认为您为 X 轴采用了不同的系列。在图表中取一个系列,例如,

<asp:Chart ID="Chart1" runat="server">
<Series>
         <asp:Series Name="Series1" XValueType="Auto" YValueType="Int32">
         </asp:Series>
</Series>
<ChartAreas>
         <asp:ChartArea Name="ChartArea1">                                
         </asp:ChartArea>
</ChartAreas>
</asp:Chart>

在这里,我在图表中采用了“Series1”。

现在用“Series1”替换你的“sName”

Chart2.Series[sName].Points.AddXY(Row["Industry"].ToString(), percentage);

Chart2.Series["Series1"].Points.AddXY(Row["Industry"].ToString(), percentage);

我认为问题应该得到解决。

于 2013-02-05T06:45:34.643 回答