MVC uses Dotnet.highcharts to do chart 01, area chart

Source: Internet
Author: User
Tags dotnet

Dotnet.highcharts is a good choice if you want to use the chart display in MVC. Dotnet.highcharts is an open source JavaScript library that supports dozens of icons such as line charts, column icons, and pie icons. This article implements a simple area chart.


Enter the keyword "dotnet.highcharts" in NuGet.

After installation, there are more highcharts related files under scripts and assemblies.


The HomeController.

usingSystem.Collections.Generic;usingSYSTEM.WEB.MVC;usingDotnet.highcharts;usingDotNet.Highcharts.Enums;usingDotNet.Highcharts.Helpers;usingDotNet.Highcharts.Options;namespacemyhighcharts.controllers{ Public classHomecontroller:controller { PublicActionResult Index () {//Create Zone 1            varSeries1 =NewSeries (); Series1. Name="Area One"; //poin Arraypoint[] Series1points =            {                NewPoint () {X =0.0, Y =0.0},                 NewPoint () {X =10.0, Y =0.0},                NewPoint () {X =10.0, Y =10.0},                NewPoint () {X =0.0, Y =10.0}            }; Series1. Data=NewData (series1points); //Create Zone 2            varSeries2 =NewSeries (); Series2. Name="Zone Two"; //Point Arraypoint[] Series2points =                {                    NewPoint () {X =5.0, Y =5.0},                    NewPoint () {X =15.0, Y =5.0},                    NewPoint () {X =15.0, Y =15.0},                    NewPoint () {X =5.0, Y =15.0}                }; Series2. Data=NewData (series2points); //Add 2 regions to a series collection            varChartSeries =NewList<series>();            Chartseries.add (SERIES1);            Chartseries.add (Series2); //Create a chart model            varChart1 =NewHighcharts ("My first area chart"); Chart1. Initchart (NewChart () {Defaultseriestype =Charttypes.area}). Settitle (NewTitle () {Text ="My first area chart"})                .            Setseries (Chartseries.toarray ()); Viewbag.chartmodel=Chart1; returnView (); }    }}

The HOME/INDEX.CSTHML.

@{Layout=NULL;}<! DOCTYPE html>"Viewport"Content="Width=device-width"/> <title>Index</title> <script src="~/scripts/jquery-2.0.0.js"></script> <script src="~/scripts/highcharts-4.0.1/js/highcharts.js"></script>@ ((DotNet.Highcharts.Highcharts) Viewbag.chartmodel)</div></body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.