繁体   English   中英

如何在C#图表控件中的饼图中设置标签格式

[英]How to format labels in a pie-chart in C# chart control

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

我的饼图控件:

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

但是无法使其正常工作。

任何帮助表示赞赏。

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

在我的图表区域:

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

在我后面的代码中:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM