在MSChart中堆栈图顶部值

时间:2011-12-23 09:07:24

标签: c# winforms mschart

我在堆叠图中添加了三个系列。我想在每个栏的顶部增加价值。不是每个系列。因为有些酒吧没有一些系列。 所以,我想在每一栏的顶部添加vaue。

            chart1.Legends.Add("Legend").Alignment = StringAlignment.Center;
            chart1.Palette = ChartColorPalette.None;
            chart1.PaletteCustomColors = new Color[] { Color.FromArgb(0, 255, 0), Color.FromArgb(0, 128, 0), Color.FromArgb(255, 0, 0), Color.Green };

            // Series for the graph.
            Series series1;
            Series series2;
            Series series3;
            Series series4;


            series1= new Series("series1");
            series12= new Series("series2");
            series13= new Series("series3");
            series14= new Series("series4");

    series1.Points.AddXY(values);
            series2.Points.AddXY(values);
    series3.Points.AddXY(values);
    series4.Points.AddXY(values);

            series1.CustomProperties = "PixelPointWidth = 17";
            series2.CustomProperties = "PixelPointWidth = 17";
            series3.CustomProperties = "PixelPointWidth = 2";
            series4.CustomProperties = "PixelPointWidth = 17";

            series3.ChartType = SeriesChartType.Line;
            series3.BorderWidth = 2;
            series3.Color = Color.Blue;

            series1.ChartType = series2 = series4.ChartType = SeriesChartType.StackedColumn;
            series1.Font = series2.Font = series3.Font = series4.Font = new Font("Verdana", 8.25f, FontStyle.Regular);

            chart1.Series.Add(series1);
            chart1.Series.Add(series2);
            chart1.Series.Add(series3);
            chart1.Series.Add(series4);

    foreach (Series series in chart1.Series) 
             {
                 if (series.Name == "series1")
                 {
                     series.ChartType = SeriesChartType.StackedColumn;
                     series["ColumnDrawingStyle"] = "series1Style";
                     series["LabelStyle"] = "Top";
                     // this willl shows the label at top of bar   
                     series.IsValueShownAsLabel = true;
                 }
             }  

1 个答案:

答案 0 :(得分:1)

我相信您希望在StackColumn之上显示一些总计,而不是像堆叠类型那样在列的中心显示。

然后最好再添加一个系列,即Total,可以说是ChartType = Bubble,然后您只能为此系列设置标签,并禁用堆叠列的成型部分。