히포차트를 asp.net MVC 어플리케이션에 추가해보자!
아래 코드는 히포차트 웹 컨트롤을 MVC 환경에서 사용 하는 방법을 소개합니다.
ViewUserControl 을 추가하고 히포차트를 도구상자에서 끌어다 놓은 후 스크립트에서 직접 c# 코드를 추가하여 히포차트를 사용할 수 있습니다.
index.cshtml
@{
ViewBag.Title = "Home Page";
}
@section featured {
<section class ="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1> @ViewBag .Title. </h1>
<h2> @ViewBag .Message </h2>
<h3> HippoChart MVC Sample</h3 >
@Html.Partial( "ViewUserControl1") <==== 히포차트 로드
</hgroup>
<p>
To learn more about ASP.NET MVC visit
<a href="http://asp.net/mvc" title ="ASP.NET MVC Website">http://asp.net/mvc</a >.
The page features <mark> videos, tutorials, and samples</mark > to help you get the most from ASP.NET MVC.
If you have any questions about ASP.NET MVC visit
<a href="http://forums.asp.net/1146.aspx/1?MVC" title ="ASP.NET MVC Forum">our forums</a >.
</p>
</div>
</section >
}
|
ViewUserControl1.ascx
<%@ Control Language="C#" Inherits ="System.Web.Mvc.ViewUserControl" %>
<%@ Register assembly="hwebchart4" namespace ="Hippo.WebForm4" tagprefix ="Hippo" %>
<Hippo: wHippoChart ID ="wHippoChart1" runat ="server" Height ="375px" Width="629px"></Hippo :wHippoChart>
<p>
<%
Hippo .SeriesList sList = new Hippo .SeriesList();
sList .ChartType = Hippo .ChartType.Spline;
Random r = new Random();
for ( int i = 0; i < 4 ; i++)
{
Hippo .Series sr = new Hippo.Series ();
sr .Line .LineWidth = 2;
sr .AreaType = Hippo .AreaType.CurvedArea;
for ( int x = 0; x < 5 ; x++)
{
Hippo .SeriesItem item = new Hippo .SeriesItem();
item .Name = x .ToString();
item .YValue = r .Next( 90);
sr .items .Add(item);
}
sList .SeriesCollection .Add(sr);
}
this.wHippoChart1 .SeriesListDictionary .Add(sList);
this.wHippoChart1 .DrawChart();
%>
</p>
|
No comments:
Post a Comment