我对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;
}
我已经阅读了网上,使用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
本文应该有所帮助:https://www.codeproject.com/Articles/820349/Highcharts-in-as-net-using-jquery-ajax。 –