【问题标题】:How to format labels in a pie-chart in C# chart control如何在 C# 图表控件的饼图中格式化标签
【发布时间】:2016-01-10 04:23:56
【问题描述】:

我遇到了一个问题,如果最大列之间的差异远大于其他列,那么饼图的标签就会相互重叠。看起来很丑。

我的饼图控件:-

<div id="demographicsCharting" class="demographicsCharting" runat="server">
        <p style="margin:10px 0 0 10px;">
            <b>Demographics of Employees:</b>
        </p>
        <asp:Chart ID="demographicsChart" runat="server" Palette="SeaGreen" Width="382px" ImageType="Jpeg" >
            <Legends>
                <asp:Legend Name="StateCategories" IsTextAutoFit="true"></asp:Legend>
            </Legends>
            <Series>
                <asp:Series Name="State" YValueType="Int32" ChartType="Pie" IsVisibleInLegend="true" >
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="Default"></asp:ChartArea>
            </ChartAreas>
        </asp:Chart>
    </div>

在服务器端:-

// Get dictionary: key-value pair for number of employees per state //
var stateArray = CreateStateDictionary(Employees);
demographicsCharting.Attributes.Add("style", "display:block");

// map all the key-value pairs to the charting asp control //
demographicsChart.Series["State"].Points.DataBindXY(stateArray.Keys, stateArray.Values);

要么我需要使我的饼图更大,以便能够为图表上的每个标签提供足够的空间。或者我需要能够将标签移出饼图并将它们放在圆周上。

我尝试过这样的事情:-

轴标签样式和格式

您可以使用 Axis 对象的 LabelStyle 属性设置轴标签样式。您在此属性中设置的标签样式属性(例如 LabelStyle.Font)适用于轴的标签。如果坐标轴标签距离太近,可以将 LabelStyle.LabelsAutoFit 或 LabelStyle.Offset 属性设置为 True。

但无法让它工作。

感谢任何帮助。

【问题讨论】:

    标签: c# charts


    【解决方案1】:

    我使用以下技术来解决我的问题。虽然不完全满意。

    在我的图表区域:-

    <ChartAreas>
                <asp:ChartArea Name="Default" Area3DStyle-Enable3D="true"></asp:ChartArea>
    </ChartAreas>
    

    在我的代码后面:-

    demographicsChart.Series["State"]["PieLabelStyle"] = "Outside";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-28
      • 1970-01-01
      • 2019-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-15
      • 1970-01-01
      相关资源
      最近更新 更多