问题描述
我使用图表Web助手在ASP.Net MVC 3,我已经看到了一系列闪亮的图像显示在网上这个API的功能,但几乎没有关于如何风格图表任何文件。例如,我需要显示图表以外的标签,我想指定百分比,而不是十进制值等。
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.
有是用于下载的web表单的项目:http://weblogs.asp.net/scottgu/archive/2010/02/07/built-in-charting-controls-vs-2010-and-net-4-series.aspx并解释非常简单的类文件如何分配值,并指定基本尺寸。
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.
据我所知,没有书已在MVC 3尚未公布,但肯定应该有某种形式的文档,解释如何使用该工具的?
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?
感谢您
编辑:
从我已阅读,ASP.Net MVC 3或者向后退了一步用绘图工具通过删除样式图表的能力,或尚未在所有记录在案。偶然发现这篇文章:<一href=\"http://forums.asp.net/t/1620783.aspx/1?ASP+NET+MVC+3+Beta+Chart+Helper+Styling+Please+Help+\">http://forums.asp.net/t/1620783.aspx/1?ASP+NET+MVC+3+Beta+Chart+Helper+Styling+Please+Help+一个非常类似的问题也在此进行描述。
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.
编辑2:
看来,微软在MVC 3,有部分实现MSCharts功能,为了使用MSCharts,该System.Web.DataVisualization装配必须导入和web.configuration文件中注册。 ŧ
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
这样,请求从视图发送到控制器。控制器生成图形图像并传回的图像效果。然后结果被显示在视图中。因为它提供了某种分离的,这非常有用。我还是不明白,为什么System.WebHelpers.Chart已经不提供此功能,但希望它会在不久的将来得到解决。
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.
修改3:
几个点使。不要构造你的图形视图 - 他们应该由控制器来提供服务。如果你决定使用意见构建图形,然后确保你在浏览文件夹更新web.config中包含&LT;添加命名空间=System.Web.UI.DataVisualization/&GT;
命名空间中的一节。集和命名空间的名字稍微有些混乱。大会呼吁:System.Web.DataVisualization当空间被称为System.Web.UI.DataVisualization。最后,我认为,图表API是伟大的,它提供的图像,这意味着图表将是所有Web浏览器访问。图表的质量是伟大的。我已经看过替代品,如融合图表,HighCharts和一些其他的jQuery / JavaScript的/闪光驱动图表。他们都试图从你把£300 - £1000,但不尝试,以满足开发者的最基本的需求。
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 <add namespace="System.Web.UI.DataVisualization"/>
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.
推荐答案
图表控件都基于一个previously单独的项目称为MS图表。
The chart controls are based off a previously separate project called MS Chart.
亚历克斯Gorev的博客(项目MSFT铅DEV):
Alex Gorev's Blog (MSFT lead dev for the project): http://blogs.msdn.com/b/alexgor/
MS图表论坛:http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/
在MSDN文档:http://msdn.microsoft.com/en-us/library/dd456632(VS.100).aspx
该职位似乎有点过时了,但API是pretty多少MS图表和新的数据可视化库之间是相同的。
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.
要解决的问题,例如:
1)要显示的图表之外的标签,每个系列
对象属性的字典数组。
1) To display labels outside the chart, each Series
object has a dictionary array of properties.
系列[PieLabelStyle] =外;
2)要指定百分比,而不是原始值,在系列
对象的标签属性采用格式化字符串。
2) To specify percentages rather than raw values, the Series
object's Label property takes a formatting string.
series.Label ={#PERCENT P0}
这些自定义属性在细节可在http://msdn.microsoft.com/en-us/library/dd456764.aspx.
These custom attributes are available in detail at http://msdn.microsoft.com/en-us/library/dd456764.aspx.
编辑:添加code示例
Adding Code Example
好吧,这是一个完整的code例子。我使用System.Web.DataVisualization V4.0.0.0,所以这应该是与MVC 3 系列
上面列出的电流不实际的 Chart.Series
属性(这是一个的SeriesCollection
)。这是个人系列
您要添加到该集合。
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.
public ActionResult TestForSOExample()
{
// slug in some data
var data = new Dictionary<string, float>
{
{"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");
}
当你调用控制器的动作,你在下面的图像psented $ P $。
When you call up the controller's action, you're presented with the following images.
这篇关于在排行榜中ASP.Net MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!