ASP.NET 图表 - 数据绑定值、自定义标签

发布于 2024-11-14 08:12:51 字数 1327 浏览 3 评论 0原文

我有一个 ASP.NET C# 数据绑定图表。数据绑定字段之一是文本,另一个是值。我希望图例显示饼图的文本,并且希望该值确定图表的形成方式,并在饼图的每块上显示为标签。

这是我到目前为止的代码:

      <asp:Chart ID="consignedChart" runat="server" DataSourceID="SqlDataSource4" 
                    BackColor="LightSlateGray" Palette="None" 
                    PaletteCustomColors="LightSeaGreen; SteelBlue" Width="400px" >
                    <Series>
                        <asp:Series Name="Series1" ChartType="Pie" XValueMember="Owner" 
                            YValueMembers="TotalValue" Legend="Legend1"  >
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                 <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true" BackColor="LightSlateGray">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic"/>
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend1">
                        </asp:Legend>
                    </Legends>
       </asp:Chart>

编辑

这是一张图片,它可能会让它更容易理解。红色框中的标签是我想要更改以显示值编号的标签。

图表

I have a databound chart in ASP.NET C#. One of the databound fields is text and the other is a value. I would like the legend to display the text for the pie chart, and I would like the value to determine how the chart is formed, and also display as a label on each piece of the pie chart.

Here is the code I have so far:

      <asp:Chart ID="consignedChart" runat="server" DataSourceID="SqlDataSource4" 
                    BackColor="LightSlateGray" Palette="None" 
                    PaletteCustomColors="LightSeaGreen; SteelBlue" Width="400px" >
                    <Series>
                        <asp:Series Name="Series1" ChartType="Pie" XValueMember="Owner" 
                            YValueMembers="TotalValue" Legend="Legend1"  >
                        </asp:Series>
                    </Series>
                    <ChartAreas>
                 <asp:ChartArea Name="ChartArea1" Area3DStyle-Enable3D="true" BackColor="LightSlateGray">
                            <Area3DStyle Enable3D="True" LightStyle="Realistic"/>
                        </asp:ChartArea>
                    </ChartAreas>
                    <Legends>
                        <asp:Legend Name="Legend1">
                        </asp:Legend>
                    </Legends>
       </asp:Chart>

EDIT

Here is an image, it might make it easier to understand. The labels in the red boxes are the ones I want changed to display the value number.

chart

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秉烛思 2024-11-21 08:12:51

我知道这个答案可能来得太晚了,请不要为此烦恼:)

我不确定您如何绑定数据,但我下载并安装了适用于 Windows 窗体示例环境的 Microsoft Chart,我可以从中学到很多东西。

这里是一个链接,您还可以从 MSDN 获取 asp.net 示例档案

我还使用 ILSpy 查看 System.Windows.Forms.DataVisualization.Charting 中的代码命名空间。这样你就可以找到很多没有记录的东西。

最后,这里有一些 winform 代码示例,您可以从中得出一些关于您的问题的想法,然后将其写入 asp.net 标记:

using System.Windows.Forms.DataVisualization.Charting;
...

// Show data points values as labels
chart1.Series["Series1"].IsValueShownAsLabel = true;

// Set axis label 
chart1.Series["Series1"].Points[2].AxisLabel = "My Axis Label\nLabel Line #2";

// Set data point label
chart1.Series["Series1"].Points[2].Label = "My Point Label\nLabel Line #2";

希望有所帮助。

I am aware this answer might come a little too late, please don't fry me for that :)

I'm not sure how you bind your data, but I downloaded and installed the Microsoft Chart for Windows Forms Samples Environment, and I could learn a lot from that.

Here is a link where you can get also asp.net samples from MSDN archives.

I am also using ILSpy to look at the code in the System.Windows.Forms.DataVisualization.Charting namespace. This way you can find about a lot of undocumented things.

Finally, here's some winform code sample from which you could draw some idea for your issue, and then write it in asp.net markup:

using System.Windows.Forms.DataVisualization.Charting;
...

// Show data points values as labels
chart1.Series["Series1"].IsValueShownAsLabel = true;

// Set axis label 
chart1.Series["Series1"].Points[2].AxisLabel = "My Axis Label\nLabel Line #2";

// Set data point label
chart1.Series["Series1"].Points[2].Label = "My Point Label\nLabel Line #2";

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文