热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

图表在ASP。净MVC3-ChartinginASP.NetMVC3

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 个解决方案

#1


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.

当您调用控制器的动作时,您将看到以下图像。

example image from controller action

#2


0  

I would recommend to render charts on the client, rather that making on the server, server is actually should be used for pulling the data from. I would use smth like google charts for that. But if you're really decided to pull charts from server, images to be specific, then the easiest is to use the above approach - Chart class. But, one disadvantage of this approach is that there is no designer for that, but actually, as I found, if you create WinForms app and drag and drop Charts control, it is exactly the same and there is a designer for that, all you need is to copy/paste designer generated code and write some processing logic, if needed. It makes life much easier.

我建议在客户机上呈现图表,而不是在服务器上创建,服务器实际上应该用于从服务器上提取数据。我会用smth,比如谷歌图表。但是,如果您真的决定从服务器上提取图表,具体来说就是图像,那么最简单的方法就是使用上面的方法——图表类。但是,这种方法的一个缺点是没有设计师,但实际上,我发现,如果你创建WinForms应用程序和拖拽控制图表,这是完全一样的,一个设计师,你只需要复制/粘贴设计师生成的代码和写一些处理逻辑,如果必要的。它使生活更容易。


推荐阅读
  • Asp.net Mvc Framework 七 (Filter及其执行顺序) 的应用示例
    本文介绍了在Asp.net Mvc中应用Filter功能进行登录判断、用户权限控制、输出缓存、防盗链、防蜘蛛、本地化设置等操作的示例,并解释了Filter的执行顺序。通过示例代码,详细说明了如何使用Filter来实现这些功能。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • 搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的详细步骤
    本文详细介绍了搭建Windows Server 2012 R2 IIS8.5+PHP(FastCGI)+MySQL环境的步骤,包括环境说明、相关软件下载的地址以及所需的插件下载地址。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • 不同优化算法的比较分析及实验验证
    本文介绍了神经网络优化中常用的优化方法,包括学习率调整和梯度估计修正,并通过实验验证了不同优化算法的效果。实验结果表明,Adam算法在综合考虑学习率调整和梯度估计修正方面表现较好。该研究对于优化神经网络的训练过程具有指导意义。 ... [详细]
  • 成功安装Sabayon Linux在thinkpad X60上的经验分享
    本文分享了作者在国庆期间在thinkpad X60上成功安装Sabayon Linux的经验。通过修改CHOST和执行emerge命令,作者顺利完成了安装过程。Sabayon Linux是一个基于Gentoo Linux的发行版,可以将电脑快速转变为一个功能强大的系统。除了作为一个live DVD使用外,Sabayon Linux还可以被安装在硬盘上,方便用户使用。 ... [详细]
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • Python开源库和第三方包的常用框架及库
    本文介绍了Python开源库和第三方包中常用的框架和库,包括Django、CubicWeb等。同时还整理了GitHub中最受欢迎的15个Python开源框架,涵盖了事件I/O、OLAP、Web开发、高性能网络通信、测试和爬虫等领域。 ... [详细]
  • 本文介绍了Sencha Touch的学习使用心得,主要包括搭建项目框架的过程。作者强调了使用MVC模式的重要性,并提供了一个干净的引用示例。文章还介绍了Index.html页面的作用,以及如何通过链接样式表来改变全局风格。 ... [详细]
  • HTML5网页模板怎么加百度统计?
    本文介绍了如何在HTML5网页模板中加入百度统计,并对模板文件、css样式表、js插件库等内容进行了说明。同时还解答了关于HTML5网页模板的使用方法、表单提交、域名和空间的问题,并介绍了如何使用Visual Studio 2010创建HTML5模板。此外,还提到了使用Jquery编写美好的HTML5前端框架模板的方法,以及制作企业HTML5网站模板和支持HTML5的CMS。 ... [详细]
  • svnWebUI:一款现代化的svn服务端管理软件
    svnWebUI是一款图形化管理服务端Subversion的配置工具,适用于非程序员使用。它解决了svn用户和权限配置繁琐且不便的问题,提供了现代化的web界面,让svn服务端管理变得轻松。演示地址:http://svn.nginxwebui.cn:6060。 ... [详细]
  • 本文记录了作者对x265开源代码的实现与框架进行学习与探索的过程,包括x265的下载地址与参考资料,以及在Win7 32 bit PC、VS2010平台上的安装与配置步骤。 ... [详细]
  • 本文讨论了在shiro java配置中加入Shiro listener后启动失败的问题。作者引入了一系列jar包,并在web.xml中配置了相关内容,但启动后却无法正常运行。文章提供了具体引入的jar包和web.xml的配置内容,并指出可能的错误原因。该问题可能与jar包版本不兼容、web.xml配置错误等有关。 ... [详细]
author-avatar
钢铁猪991884679
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有