2017-08-24 34 views
0

我對Web服務非常陌生,最近我剛開始開發一種從樹莓派接收數據的服務。所有從Raspberry Pi發送的數據都存儲在Microsoft SQL服務器中,我已經與我的Web服務建立了連接。現在,當我點擊一個超鏈接時,我可以查看數據,但是以json格式的記事本出現。以下是我的控制器代碼:將數據顯示到Web服務中的圖形中ASP.NET MVC框架

namespace HelloWorld.Controllers 
{ 
    public class SecondlyReadingDatasController : ApiController 
    { 

     private cloudsqlEntities db = new cloudsqlEntities(); 

     // GET: api/SecondlyReadingDatas 
     public IQueryable<SecondlyReading> GetSecondlyReadings() 
     { 
      SecondlyReading sec = db.SecondlyReadings.First(); 
      return db.SecondlyReadings; 
     } 

下面是我試圖檢索數據的圖像: enter image description here

我已經閱讀了網上,使用Ajax和Highcharts可以用來顯示數據,但是,我真的很困惑。

我的主要問題是:

  • 在哪裏實現對Ajax特性的代碼?在 Index.cshtml or_Layout.cshtml?
  • 我是否需要在我的模型或控制器中添加任何東西?
  • 我是否需要安裝任何軟件包或庫?我已經安裝了 DotNet.HighCharts已經

我試圖把下面的代碼在_Layout.cshtml,但是,我沒有得到任何東西:

<script type="text/javascript"> 
$.ajax({ 
    url: 'http://localhost/TestWebsite/api/SecondlyReadingDatas', 
    success: function(singleSeries) { 
    Highcharts.chart('container', { 
     series: [singleSeries] 
    }); 
    } 
}); 
</script> 

我不知道這是否是完整的只需要的代碼集。我試着看下面的鏈接,但是我很難理解,因爲這是我第一次使用Ajax。希望得到任何援助

參考鏈接:

http://www.c-sharpcorner.com/UploadFile/1f3f2a/charting-in-mvc/

https://docs.microsoft.com/en-us/aspnet/web-pages/overview/data/7-displaying-data-in-a-chart

https://www.codeproject.com/Articles/820349/Highcharts-in-asp-net-using-jquery-ajax Load data into Highcharts with Ajax

https://csharptrenches.wordpress.com/2013/08/21/how-to-use-highcharts-js-with-asp-net-mvc-4/

creating highchart with ajax json data

HighCharts load data via ajax

+0

本文應該有所幫助:https://www.codeproject.com/Articles/820349/Highcharts-in-as-net-using-jquery-ajax。 –

回答

0

在你的腳本,你有一個元素(contianer)將包含圖表的ID,以取代「容器」 ......

Highcharts.chart('container', { 

所以,如果你有一個

<div id='chartContainer'></div> 

然後你可以改變它;

Highcharts.chart('chartContainer', { 
+0

我在哪裏放置Highcharts.chart('chartContainer',{ – gram95

相關問題