简体   繁体   English

在asp.net mvc 3中使用highcharts库

[英]using library highcharts with asp.net mvc 3

I want to use the library highcharts with asp.net mvc 3 but the examples that I have found in the web is with asp.net mvc 2. The other thing is, how can I pass the result data from a linq query to a highcharts´s serie in my application. 我想将highcharts库与asp.net mvc 3一起使用,但是我在网上找到的示例是asp.net mvc2。另一件事是,如何将结果数据从linq查询传递到highcharts在我的应用程序中是意甲。

And anyone that can provide an example of highcharts with asp.net mvc 3? 有人能用asp.net mvc 3提供highcharts示例吗?

Another way to do this is by using DotNet.Highcharts library. 另一种方法是使用DotNet.Highcharts库。 You can build the Highchart entirely on the server side and there are a lot of MVC3 samples . 您可以完全在服务器端构建Highchart,并且有很多MVC3示例

A good way to do this is to configure your chart object using static Javascript and then load your chart series as JSON data using Ajax and the addSeries method. 一个好的方法是使用静态Javascript配置图表对象,然后使用Ajax和addSeries方法将图表系列作为JSON数据addSeries You can use the Controller.Json method to return your LINQ results as JSON. 您可以使用Controller.Json方法将LINQ结果作为JSON返回。 Assuming you are passing a numeric array to the Controller.Json method in your AJAX action, the following is a simple example of the JavaScript needed to do this: 假设您将数字数组传递给AJAX操作中的Controller.Json方法,下面是执行此操作所需的JavaScript的简单示例:

$(document).ready(function() {
   var chart = new Highcharts.Chart({
      chart: {
         renderTo: "<chart-div>"
      },
      title: { text: "Test Chart" },
   });
   $.ajax({
      url: "<query-url>",
      success: function(result) {
         chart.addSeries({
            data: result,
         });
      }
   });
});

Replace <chart-div> with your container and <query-url> with your Ajax URL or a call to UrlHelper.Action . <chart-div>替换<chart-div>容器,将<query-url>替换为您的Ajax URL或对UrlHelper.Action

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM