图表系列标签为百分比

Chart series label as a percent

我通过 System.Web.UI.DataVisualization.Charting 在 MS Visual Studio 2010 中使用图表组件。我在使用柱形图时遇到问题,我想在其中将标签显示为百分比。该图显示了全年每个月的决策数量(正面 - 绿色,负面 - 红色,中性 - 蓝色)。麻烦的是,如果我使用以下命令...

ChartDecisionDyn.Series["Positive"].IsValueShownAsLabel = true;
ChartDecisionDyn.Series["Positive"].Label = "#PERCENT";

...我没有得到预期的百分比结果。显示的结果表示某个月的积极决定数/全年的积极决定数,但我想要的结果是某个月的积极决定数/某个月的总决定数。有人有什么建议吗?在此先感谢您的帮助。

你可以看到我的图表详情here

ChartDecisionDyn.Series["Positive"].LabelFormat="#.00′ %'";

一样使用ChartDecisionDyn.Series["Positive"].LabelFormat

我的理解是这些选项是相互排斥的。第二个将覆盖第一个。怎么设置IsValueShownAsLabel=true,设置正点的值=positive/(positive+negative+neutral)*100

或设置系列 Label="#LABEL" 并且在添加点的值时还添加等于 positive/(positive+negative+neutral)*100 的点标签作为字符串

看不到你图表的图像,但我这样做了:

<asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1" Width="451px">
    <Series>
        <asp:Series Name="Series1" XValueMember="Month" YValueMembers="Percentage"></asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
            <AxisY>
                <LabelStyle Format="P0" />
            </AxisY>
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>

或者这个:

    Chart1.ChartAreas[0].AxisY.LabelStyle.Format = "P0";

得到这个:

编辑:这个怎么样:

<asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1" Width="451px">
    <Series>
        <asp:Series Name="Series1" XValueMember="Month" YValueMembers="Percentage" IsValueShownAsLabel="True" LabelFormat="F2"></asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
            <AxisY>
                <MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
                <LabelStyle Format="P0" />
            </AxisY>
            <AxisX>
                <MajorGrid Enabled="False" />
            </AxisX>
        </asp:ChartArea>
    </ChartAreas>
</asp:Chart>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="WebApplication9.DataPoint" DeleteMethod="Remove" InsertMethod="Add" SelectMethod="ToArray" TypeName="WebApplication9.DataPointList" UpdateMethod="Add"></asp:ObjectDataSource>

编辑 2:添加多个系列。

<asp:Chart ID="Chart1" runat="server" DataSourceID="ObjectDataSource1" Width="499px">
    <Series>
        <asp:Series Name="Percent" XValueMember="Month" YValueMembers="Percent" IsValueShownAsLabel="True" LabelFormat="P0" Legend="Legend1" YAxisType="Secondary"></asp:Series>
        <asp:Series ChartArea="ChartArea1" IsValueShownAsLabel="True" LabelFormat="N0" Legend="Legend1" Name="Positive" XValueMember="Month" YValueMembers="Positive">
        </asp:Series>
        <asp:Series ChartArea="ChartArea1" IsValueShownAsLabel="True" LabelFormat="N0" Legend="Legend1" Name="Neutral" XValueMember="Month" YValueMembers="Neutral">
        </asp:Series>
        <asp:Series ChartArea="ChartArea1" IsValueShownAsLabel="True" LabelFormat="F0" Legend="Legend1" Name="Negative" XValueMember="Month" YValueMembers="Negative">
        </asp:Series>
    </Series>
    <ChartAreas>
        <asp:ChartArea Name="ChartArea1">
            <AxisY>
                <MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
            </AxisY>
            <AxisX>
                <MajorGrid Enabled="False" />
            </AxisX>
            <AxisY2>
                <MajorGrid LineColor="DarkGray" LineDashStyle="Dot" />
                <LabelStyle Format="P0" />
            </AxisY2>
        </asp:ChartArea>
    </ChartAreas>
    <Legends>
        <asp:Legend Alignment="Center" Docking="Top" Name="Legend1">
        </asp:Legend>
    </Legends>
</asp:Chart>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DataObjectTypeName="WebApplication11.DecisionPoint" DeleteMethod="Remove" InsertMethod="Add" SelectMethod="ToArray" TypeName="WebApplication11.DecisionPointList"></asp:ObjectDataSource>