C#中的标签Pie / Dougnhut图表

时间:2016-03-09 17:36:58

标签: c# asp.net charts

我正在生成甜甜圈图表,但在某些情况下,行标签百分比已关闭,在某些情况下,百分比符号也会关闭。

Donut Charts

我该如何解决这个问题?

- 代码

        chart.Series["Data"].ChartType = SeriesChartType.Doughnut;
        chart.Series["Data"]["PieLineColor"] = "LightGray";
        chart.Series["Data"]["DoughnutRadius"] = "30";
        chart.Series["Data"]["PieStartAngle"] = "270";
        chart.ChartAreas[0].InnerPlotPosition.Height = 90;
        chart.ChartAreas[0].InnerPlotPosition.Width = 90;
        chart.ChartAreas[0].Area3DStyle.Enable3D = true;
        chart.ChartAreas[0].Area3DStyle.Inclination = 0;
        chart.Series["Data"].Label = "#PERCENT{P0}";
        chart.Series["Data"].LegendText = "#VALX";
        chart.Series["Data"].Font = new Font("Arial", 16.0f,    FontStyle.Bold);

1 个答案:

答案 0 :(得分:0)

Html code:   
  <asp:Chart ID="Chart1" runat="server" Height="300px" Width="400px"  >
            <Titles>
                <asp:Title ShadowOffset="3" Name="Items" />
            </Titles>
            <Legends>
                <asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Default" 
                    LegendStyle="Row"  />
            </Legends>
            <Series>
                <asp:Series Name="Data" Color="Chocolate" BackGradientStyle="HorizontalCenter"   />
            </Series>
            <ChartAreas >
                <asp:ChartArea Name="ChartArea1"  BorderWidth="0" BackColor="White"   />
            </ChartAreas>
        </asp:Chart> 

    Code behind:
    chart.Series["Data"].ChartType = SeriesChartType.Doughnut;
    chart.Series["Data"]["PieLabelStyle"] = "outside";
    chart.Series["Data"]["PieLineColor"] = "LightGray";
    chart.Series["Data"]["DoughnutRadius"] = "30";
    chart.Series["Data"]["PieStartAngle"] = "270";
    chart.ChartAreas[0].InnerPlotPosition.Height = 90;
    chart.ChartAreas[0].InnerPlotPosition.Width = 90;
    chart.ChartAreas[0].Area3DStyle.Enable3D = true;
    chart.ChartAreas[0].Area3DStyle.Inclination = 0;
    chart.Series["Data"].Font = new Font("Arial", 16.0f,    FontStyle.Bold);
    foreach (DataPoint p in chart.Series["Data"].Points)
                    {
                        p.Label = "#PERCENT";
                        p.LabelToolTip = "#VALX";
                        p.LabelForeColor = Color.Brown;
                        p.LegendText = "#VALX";
                        p.LegendToolTip = "#PERCENT";
                        p.LabelToolTip = "#PERCENT\n#VALX";

                    }

只在下面添加foreach循环到您当前的.cs代码 这将为您的Pie / Dougnhut图表添加标签和工具提示。 如果您在执行此操作时遇到任何问题,请与我们联系。