2015-01-14 3 views
0

Я следую этому руководству, в котором обсуждается привязка данных к серверу sql с помощью WebForms. Я ввел необработанные данные, чтобы показать, что диаграммы работают до добавления привязки данных. Однако при запуске проекта диаграмма не отображается. Я добавил DotNet.HighCharts, используя NuGet в VS2012. Любая идея, почему диаграмма не отображается? Вот код для моего Default.aspx.csДиаграмма не отображается с использованием DotNet.HighCharts и WebForms

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> 
+0

Извините, забыли добавить учебное пособие, за которым я следую: http://www.balsamino.com/component/k2/item/20-highcharts-databinding-in-c – bearaman

ответ

0

Решение это просто. Вы забыли импортировать библиотеки highcharts.js и ajax.

<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> 

    <!-- IMPORT THE JAVASCRIPT LIBRARIES HERE --> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
    <script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script> 
    <script type="text/javascript" src="http://code.highcharts.com/modules/exporting.js"></script> 

    <asp:Literal id="ltChart1" runat="server"></asp:Literal> 
</asp:Content> 
1

Если вы используете Site.Master файл, чтобы добавить путь к файлам JavaScript, убедитесь, что вы добавили путь этих трех файлов JavaScript.

<asp:ScriptManager runat="server"> 
     <Scripts>    
      <asp:ScriptReference Path="~/Scripts/highcharts.js" /> 
      <asp:ScriptReference Path="~/Scripts/jquery-1.5.1.min.js" /> 
      <asp:ScriptReference Path="~/Scripts/exporting.js" />    
     </Scripts> 
    </asp:ScriptManager> 

Проверьте этот учебник: http://dotnethighcharts.codeplex.com/ Здесь объясняется как для MVC и Web Forms.

 Смежные вопросы

  • Нет связанных вопросов^_^