我正在关注本教程,该教程讨论了使用 WebForms 将数据绑定到 sql 服务器。在添加数据绑定之前,我输入了原始数据以显示图表正在工作。但是,当我运行项目时没有显示图表。我在 VS2012 中使用 NuGet 添加了 DotNet.HighCharts。知道为什么图表没有被渲染吗?这是我的 Default.aspx.cs 的代码
namespace HighChartsWebForms
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
Render_Chart();
}
protected void Render_Chart()
{
Object[] chartValues = new Object[8]; // declare an object for the chart rendering
DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart")
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Line })
.SetTitle(new Title
{
Text = "Data",
X = -20
})
.SetSubtitle(new Subtitle
{
Text = "Source: Static data",
X = -20
})
.SetXAxis(new XAxis
{
Categories = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug" }
})
.SetSeries(new[]
{
new Series
{
Name = "# Pizza",
Data = new Data(new object[] { 2, 3, 5, 7, 6, 6, 7, 8 }),
},
});
ltChart1.Text = chart.ToHtmlString();
}
}
}
这是我的 Default.aspx:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HighChartsWebForms._Default" %>
<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1><%: Title %>.</h1>
<h2>Testing HighCharts with ASP.NET</h2>
</hgroup>
</div>
</section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<h3>This should show a chart:</h3>
<asp:Literal id="ltChart1" runat="server"></asp:Literal>
</asp:Content>