如何更改图表的视角和标签值 .NET C#

发布于 2024-10-18 14:12:37 字数 1720 浏览 2 评论 0原文

简短描述

我正在将图表用于特定应用程序,在该应用程序中我需要更改渲染的 3D 饼图的视角和自动标签的值,从饼图标签名称更改为相应的饼图值。

图表如下所示: Pie Chart


初始化

这是我初始化它的方式:

    Dictionary<string, decimal> secondPersonsWithValues = HistoryModel.getSecondPersonWithValues();
    decimal[] yValues = new decimal[secondPersonsWithValues.Values.Count]; //VALUES
    string[] xValues = new string[secondPersonsWithValues.Keys.Count]; //LABELS
    secondPersonsWithValues.Keys.CopyTo(xValues, 0);
    secondPersonsWithValues.Values.CopyTo(yValues, 0);
    incomeExpenseChart.Series["Default"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
    incomeExpenseChart.Series["Default"].Points.DataBindXY(xValues, yValues);
    incomeExpenseChart.ChartAreas["Default"].Area3DStyle.Enable3D = true;
    incomeExpenseChart.Series["Default"].CustomProperties = "PieLabelStyle=Outside";
    incomeExpenseChart.Legends["Default"].Enabled = true;
    incomeExpenseChart.ChartAreas["Default"].Area3DStyle.LightStyle = System.Windows.Forms.DataVisualization.Charting.LightStyle.Realistic;
    incomeExpenseChart.Series["Default"]["PieDrawingStyle"] = "SoftEdge";

基本上我使用 HistoryModel.getSecondPersonWithValues( );Dictionary 形式获取对,其中 keypersonvalue > 是金额


问题#1

我需要的是能够将标记的标签从人名更改为金额或添加另一个具有相同颜色的金额标签(参见图片)。 在此处输入图像描述


问题 #2

另一个问题是我需要更改 3D 饼图的视角。也许它非常简单,我只是不知道所需的属性,或者也许我需要重写一些绘制事件。无论哪种方式,任何一种方式都会被应用。

预先感谢乔治。

Short Description

I am using charts for a specific application where i need to change the view angle of the rendered 3D Pie chart and value of automatic labels from pie label names to corresponding pie values.

This how the chart looks:
Pie Chart


Initialization

This is how i initialize it:

    Dictionary<string, decimal> secondPersonsWithValues = HistoryModel.getSecondPersonWithValues();
    decimal[] yValues = new decimal[secondPersonsWithValues.Values.Count]; //VALUES
    string[] xValues = new string[secondPersonsWithValues.Keys.Count]; //LABELS
    secondPersonsWithValues.Keys.CopyTo(xValues, 0);
    secondPersonsWithValues.Values.CopyTo(yValues, 0);
    incomeExpenseChart.Series["Default"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
    incomeExpenseChart.Series["Default"].Points.DataBindXY(xValues, yValues);
    incomeExpenseChart.ChartAreas["Default"].Area3DStyle.Enable3D = true;
    incomeExpenseChart.Series["Default"].CustomProperties = "PieLabelStyle=Outside";
    incomeExpenseChart.Legends["Default"].Enabled = true;
    incomeExpenseChart.ChartAreas["Default"].Area3DStyle.LightStyle = System.Windows.Forms.DataVisualization.Charting.LightStyle.Realistic;
    incomeExpenseChart.Series["Default"]["PieDrawingStyle"] = "SoftEdge";

Basically i am querying data from database using the HistoryModel.getSecondPersonWithValues(); to get pairs as Dictionary<string, decimal> where key is the person and value is ammount.


Problem #1

What i need is to be able to change the marked labels from person names to the ammounts or add another label of ammounts with the same colors (See Image).
enter image description here


Problem #2

Another problem is that i need to change the view angle of 3D Pie chart. Maybe it's very simple and I just don't know the needed property or maybe i need to override some paint event. Either ways any kind of ways would be appriciated.

Thanks in advance George.

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

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

发布评论

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

评论(2

怎会甘心 2024-10-25 14:12:37

问题 #1 的解决方案

添加新标签并填充自定义值会有所帮助。
此外,我更改了


问题#2的Series.IsValueShownAsLabel = true;解决方案

我应该设置ChartArea.Area3DStyle.IsClustered = true;,然后设置ChartArea.Area3DStyle.Inclination;

Solution for Problem #1

Adding new Label and filling with custom values helped.
In addition i changed the Series.IsValueShownAsLabel = true;


Solution for Problem #2

I should have set the ChartArea.Area3DStyle.IsClustered = true; and then set the ChartArea.Area3DStyle.Inclination;

巴黎盛开的樱花 2024-10-25 14:12:37

使用 xlhart.Rotation 和 xlchart.Elevation。

Use xlhart.Rotation and xlchart.Elevation.

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