0

私はこれを見るためにチャートを生成しようとしています ここに画像の説明を入力

私はほとんどそこにいますが、解決できない問題がいくつかあります。列は、それらの間のスペースを分離せずに表示されています! また、一番下にあるカスタム ラベルが各列に揃えられていません。

これは、既存のコードから得られる出力です

ここに画像の説明を入力

そのため、1) x 軸全体に列を広げる必要があります。2) カスタム ラベルを各列に合わせます。

この問題に関するヘルプまたはフィードバックに感謝します

これは、現在の画像を生成するコードです。私のデータセット「ds」には次のような値があることに注意してください

Emerging 28.45646456 Dent 14.1456465 Audio 27.456456 Cosmetic 43.44564456 Vet 35.15465646645

public void GenerateChart(){

    //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

I think you took the different series for the X-Axis. Take a single series in your chart like,

<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>

Here I have taken "Series1" in chart.

Now replace your "sName" with "Series1"

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

to

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

I think problem should be solved.

于 2013-02-05T06:45:34.643 に答える