如何更改使用 Razor 图表助手创建的图表中的图表参数(例如饼图切片颜色)?
我按照 ASP.NET Razor Pages 指南生成ASP.NET MVC 3 视图中的图表。
我可以生成/显示饼图。但我不知道如何更改饼图幻灯片的颜色 - 或分解切片。
我尝试引用 Chart 对象的“Series”集合,但似乎没有一个。
这是我目前拥有的代码片段。
<td>
@{
Chart chart =
new Chart(width: 100, height: 100)
.AddSeries(chartType: "Pie", name: "Dafault", xValue: new[] { "Yes", "No" }, yValues: new[] { 70.2m, 29.8m });
chart.Write();
}
</td>
谁能告诉我该怎么做?
I'm following the ASP.NET Razor Pages guide to generate charts in an ASP.NET MVC 3 view.
I can generate/display a pie chart. But I can't see how to change the colors of the pie slides - or explode a slice.
I've tried to reference the "Series" collection of the Chart object, but there doesn't see to be one.
Here's the code snippet I currently have.
<td>
@{
Chart chart =
new Chart(width: 100, height: 100)
.AddSeries(chartType: "Pie", name: "Dafault", xValue: new[] { "Yes", "No" }, yValues: new[] { 70.2m, 29.8m });
chart.Write();
}
</td>
Can anyone tell me how I'd go about this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Dommer,
我只比您领先一步,但是您可以使用图表构造函数中的“themePath”属性创建自定义颜色。虽然没有详细记录,但 themePath 是详细描述图表的 XML 文档的路径。您可以通过对主题中的字符串 const(这是 Chart 构造函数中的可选第三个参数)执行智能感知来获取 XML 示例。
您可以在以下链接中找到对 themePath 值和示例 XML 的引用:
http://www.mikepope.com/blog/documents/WebHelpersAPI.html#Chart
现在自定义颜色。主题文件中的 XML 显示 Chart 元素中的 Palette 属性。将其设置为“None”,并添加包含 RGB 值集合的“PaletteCustomColors”属性,如下所示:
PaletteCustomColors='0,0,255; 0,255,0; 255,0,0; 0,255,255; 255,0,255; 255,255,0'
在构造函数中引用您的 themePath,如下所示:
这应该可以做到。顺便说一句,主题协议似乎使用了许多属于 System.Web.UI.DataVisualization.Chart 中的属性的属性。您可以通过调整和添加/删除属性来进行实验(正如我目前正在做的那样),看看什么会改变图表的外观以及什么会破坏它。解析器对于它接受的属性非常挑剔。
希望这有帮助。
吉姆·斯坦利
Blackboard Connect 公司
Dommer,
I'm only one step ahead of you here, but you can create custom colors using the "themePath" property in the Chart's constructor. It's not well documented, but the themePath is a path to an XML document that describes the chart in detail. You can get samples of the XML by doing intellisense on the string consts in the Theme (which is an optional third parameter in Chart's constructor).
You can find a reference to themePath values and sample XML at the following link:
http://www.mikepope.com/blog/documents/WebHelpersAPI.html#Chart
Now to custom colors. The XML in the theme files shows a Palette attribute in the Chart element. Set that to 'None', and add a 'PaletteCustomColors' attribute with a collection of RGB values like so:
PaletteCustomColors='0,0,255; 0,255,0; 255,0,0; 0,255,255; 255,0,255; 255,255,0'
Refer to your themePath in the contsructor like so:
This should do it. As an aside, it appears that the theming protocol uses a lot of attributes that are properties in the System.Web.UI.DataVisualization.Chart. You can experiment (as I'm currently doing) by tweaking and adding/removing attributes to see what will change the look of your chart and what will break it. The parser is very persnickety about the attributes it accepts.
Hope this helps.
Jim Stanley
Blackboard Connect Inc.
您正在使用 System.Web.Helpers 命名空间下提供的图表。您将需要 System.Web.UI.DataVisualization 命名空间下可用的完整图表组件。
这是开始的链接
使用 MVC 绘制图表
以下是有关如何使用具有交互性的完整图表功能的链接。
交互式图表
You are using Charting available under System.Web.Helpers namespace. You will need a full charting component available under System.Web.UI.DataVisualization namespace.
Here is the link to get started
Charting with MVC
Here is the link on how to use full blow charting features with interactivity.
Charting with interactivity