如何更改图表的视角和标签值 .NET C#
简短描述
我正在将图表用于特定应用程序,在该应用程序中我需要更改渲染的 3D 饼图的视角和自动标签的值,从饼图标签名称更改为相应的饼图值。
图表如下所示:
初始化
这是我初始化它的方式:
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
形式获取对,其中 key 是 person 和 value > 是金额。
问题#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:
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).
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题 #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 theChartArea.Area3DStyle.Inclination;
使用 xlhart.Rotation 和 xlchart.Elevation。
Use
xlhart.Rotation
andxlchart.Elevation
.