作者:钢铁猪991884679 | 来源:互联网 | 2023-05-19 10:31
ImusingChartwebhelperinASP.NetMVC3.Ihaveseenarangeofshinyimagesonlineshowingcapa
I'm using Chart web helper in ASP.Net MVC 3. I have seen a range of shiny images online showing capabilities of this API, but there is hardly any documentation on how to style the charts. For example, I need to display labels outside of the chart, I'd like to specify percentage, rather than decimal values, etc.
我在ASP中使用了Chart web helper。净MVC 3。我在网上看到了一系列闪亮的图片,展示了这个API的功能,但是几乎没有任何文档说明如何对图表进行样式化。例如,我需要在图表之外显示标签,我想指定百分比,而不是十进制值,等等。
There is a webforms project for download: http://weblogs.asp.net/scottgu/archive/2010/02/07/built-in-charting-controls-vs-2010-and-net-4-series.aspx and very simple class documentation that explains how to assign values and specify basic dimensions.
有一个用于下载的webforms项目:http://weblogs.asp.net/scottgu/archive0/02/07/built -in-charting-controls-vs-2010-and-net-4-series.aspx和非常简单的类文档,说明如何分配值和指定基本维度。
I understand that no books have been published yet on MVC 3, but surely there should be some sort of documentation explaining how to use the tool?
我知道目前还没有关于MVC 3的书籍出版,但是肯定应该有某种文档说明如何使用这个工具?
Thank you
谢谢你!
EDIT:
编辑:
From what I have read, ASP.Net MVC 3 either took a step back with charting tool by removing ability to style charts, or it has not been documented at all. Came across this article: http://forums.asp.net/t/1620783.aspx/1?ASP+NET+MVC+3+Beta+Chart+Helper+Styling+Please+Help+ , a very similar issue is described there.
根据我所读到的,ASP。Net MVC 3要么通过删除图表样式工具后退一步,要么完全没有文档记录。本文简介:http://forums.asp.net/t/1620783.aspx/1?+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (+ + + + + + + + + + + + + + + + + + + + +
EDIT 2: It appears that Microsoft have partially implemented MSCharts functionality in MVC 3. In order to use MSCharts, the System.Web.DataVisualization assembly must be imported and registered in web.configuration file. T
编辑2:看起来微软在MVC 3中已经部分实现了MSCharts功能。为了使用MSCharts, System.Web。必须在web中导入和注册数据化程序集。配置文件。T
This way, requests are sent from view to controllers. Controllers generate image of a graph and pass back an image result. Result is then displayed in the view. This is useful as it provides some sort of seperation. I still don't understand why System.WebHelpers.Chart does not already offer this functionality, but hopefully it will be addressed in near future.
这样,请求从视图发送到控制器。控制器生成图形的图像并传回图像结果。然后在视图中显示结果。这是有用的,因为它提供了某种分离。我还是不明白为什么是system . webhelper。图表还没有提供这个功能,但是希望在不久的将来能解决这个问题。
EDIT 3: Few more points to make. Don't construct your graphs in the view - they should be served by a controller. If you do decide to use views for constructing graphs, then make sure you update web.config in Views folder to include
in the namespace section. Names of assemblies and namespaces are slightly confusing. Assembly is called: System.Web.DataVisualization when namespace is called System.Web.UI.DataVisualization. Finally I think that charting API is great, it serves images which means that charts will be accessible from all web browsers. Quality of the charts is great. I have looked at alternatives such as Fusion Charts, HighCharts and few other jQuery/Javascript/Flash powered charts. They all try to take £300-£1000 from you without trying to meet the most basic needs of developers.
编辑3:再讲几个要点。不要在视图中构造图形——它们应该由控制器提供。如果您决定使用视图构建图形,那么请确保更新web。在视图文件夹中配置包含 <添加名称空间="system.web.ui。命名空间部分中的“ />”。程序集和名称空间的名称有点混乱。大会被称为:包含。当命名空间被称为System.Web.UI.DataVisualization时,就称为DataVisualization。最后,我认为绘图API很好,它提供图像,这意味着所有web浏览器都可以访问图表。图表的质量很好。我已经研究过其他的方法,比如融合图、HighCharts和其他一些jQuery/Javascript/Flash支持的图表。他们都试图获得£300 -£1000你没有试图满足开发人员的最基本的需求。
2 个解决方案
35
The chart controls are based off a previously separate project called MS Chart.
图表控件是基于一个以前称为MS图表的独立项目。
Alex Gorev's Blog (MSFT lead dev for the project): http://blogs.msdn.com/b/alexgor/
Alex Gorev的博客(MSFT lead dev for the project): http://blogs.msdn.com/b/alexgor/
MS Chart Forums: http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/
女士表论坛:http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/
Documentation on MSDN: http://msdn.microsoft.com/en-us/library/dd456632(VS.100).aspx
在MSDN文档:http://msdn.microsoft.com/en-us/library/dd456632(VS.100). aspx
The posts seem a bit out of date, but the API is pretty much the same between MS Chart and the new Data Visualization libraries.
这些文章似乎有点过时,但是MS图表和新的数据可视化库之间的API几乎是一样的。
To address your example questions:
要解决示例问题,请:
1) To display labels outside the chart, each Series
object has a dictionary array of properties.
1)为了显示图表外的标签,每个系列对象都有一个属性字典数组。
series["PieLabelStyle"] = "Outside";
系列(“PieLabelStyle”)=“外”;
2) To specify percentages rather than raw values, the Series
object's Label property takes a formatting string.
要指定百分比而不是原始值,Series对象的Label属性采用格式化字符串。
series.Label = "#PERCENT{P0}"
系列。Label = " # % { P0 }”
These custom attributes are available in detail at http://msdn.microsoft.com/en-us/library/dd456764.aspx.
这些自定义属性可以在http://msdn.microsoft.com/en-us/library/dd456764.aspx上获得详细信息。
EDIT: Adding Code Example
编辑:添加代码的例子
Okay, here's a full code example. I'm using System.Web.DataVisualization v4.0.0.0, so this should be current with MVC 3. The series
listed above isn't the actual Chart.Series
properties (that's a SeriesCollection
). It's the individual series
that you're adding to that collection.
这里有一个完整的代码示例。我用包含。datavialization v4.0.0.0,所以这应该是当前的MVC 3。上面列出的系列不是实际的图表。系列属性(这是一个SeriesCollection)。它是你要添加到那个集合中的单个系列。
public ActionResult TestForSOExample()
{
// slug in some data
var data = new Dictionary
{
{"test", 10.023f},
{"test2", 20.020f},
{"test3", 19.203f},
{"test4", 4.039f},
{"test5", 5.343f}
};
var chart = new Chart();
var area = new ChartArea();
// configure your chart area (dimensions, etc) here.
chart.ChartAreas.Add(area);
// create and customize your data series.
var series = new Series();
foreach (var item in data)
{
series.Points.AddXY(item.Key, item.Value);
}
series.Label = "#PERCENT{P0}";
series.FOnt= new Font("Segoe UI", 8.0f, FontStyle.Bold);
series.ChartType = SeriesChartType.Pie;
series["PieLabelStyle"] = "Outside";
chart.Series.Add(series);
var returnStream = new MemoryStream();
chart.ImageType = ChartImageType.Png;
chart.SaveImage(returnStream);
returnStream.Position = 0;
return new FileStreamResult(returnStream, "image/png");
}
When you call up the controller's action, you're presented with the following images.
当您调用控制器的动作时,您将看到以下图像。