The quick start guides you through the steps of adding DashboardLayout control to your MVC web application for creating a simple dashboard application. Follow the steps given below to get started:
Create a new MVC application using the ComponentOne or VisualStudio templates. For more information about creating an MVC application, see Configuring your MVC Application topic.
ProductDashboardData.cs
). For more information on how to add a new model, see Adding Controls.ProductDashboardData.cs
model. We are using ProductDashboardData
class to represent data.
C# |
コードのコピー
|
---|---|
using System; using System.Collections.Generic; using System.Linq; namespace Dashboard_Quickstart.Models { public class ProductDashboardData { private IEnumerable<ProductData> _productDetails = null; public IEnumerable<ProductData> ProductDetails { get { if (_productDetails == null) { _productDetails = GetProductData(); } return _productDetails; } } public IEnumerable<ProductData> GetProductData() { var rand = new Random(0); var productID = new[] { "PR001", "PR002", "PR003", "PR004", "PR005" }; var products = new[] { "Ipoh Coffee", "Vegie-Spread", "Ikura", "Filo Mix", "Geitost" }; var categories = new[] { "Beverages", "Confections", "Seafood", "Cereals", "Dairy Products" }; var list = products.Select((p, i) => { int stockunits = rand.Next(1, 6); int orderunits = rand.Next(1, 9); int sales = rand.Next(1, 6); return new ProductData { ProductID = productID[i], ProductName = p, Category = categories[i], UnitsInStock = stockunits, UnitsOnOrder = orderunits, Sales = sales, ReorderLevel = true }; }); return list; } } public class ProductData { public string ProductID { get; set; } public string ProductName { get; set; } public string Category { get; set; } public int UnitsInStock { get; set; } public int UnitsOnOrder { get; set; } public int Sales { get; set; } public bool ReorderLevel { get; set; } } } |
Steps to add a DashboardLayout control to the application, are as follows:
Add a new Controller
DashboardLayoutController
).C# |
コードのコピー
|
---|---|
using <ApplicationName>.Models;
|
DashboardLayoutController.cs |
コードのコピー
|
---|---|
public ActionResult Index() { ProductDashboardData data = new ProductDashboardData(); return View(data.ProductDetails); } |
DashboardLayoutController.
Index()
.Index.cshtml |
コードのコピー
|
---|---|
@using ApplicationName.Models @model IEnumerable<ProductData> <style> .wj-dashboard .wj-flexchart { margin: 0px; padding: 4px; border: none; height: 240px; } </style> <br /> <div> @(Html.C1().FlexPie<ProductData>().Id("CategorySales") .Bind("Category", "Sales", Model) ) @(Html.C1().FlexChart().Id("ProductsStock") .Bind("ProductName", Model) .ChartType(C1.Web.Mvc.Chart.ChartType.Column) .Series(sers => { sers.Add() .Binding("UnitsInStock") .Name("Stock Units"); }) .Series(sers => { sers.Add() .Binding("UnitsOnOrder") .Name("OrderUnits"); }) ) @(Html.C1().FlexGrid<ProductData>().Id("ProductDetails") .AutoGenerateColumns(false) .Bind(Model) .Columns(bl => { bl.Add(cb => cb.Binding("ProductID").Width("150").Align("Center")); bl.Add(cb => cb.Binding("ProductName").Width("150")); bl.Add(cb => cb.Binding("Category").Width("150")); bl.Add(cb => cb.Binding("ReorderLevel").Width("150")); }) ) </div> @(Html.C1().DashboardLayout().Id("SampleDashboard") .AttachFlowLayout(flb => flb.Direction(FlowDirection.LeftToRight) .Items(isb => { isb.Add(ftb => ftb.HeaderText("Category Sales") .Content("#CategorySales").Width(450).Height(300)); isb.Add(ftb => ftb.HeaderText("Products Stock") .Content("#ProductsStock").Width(450).Height(300)); isb.Add(ftb => ftb.HeaderText("Product Details") .Content("#ProductDetails").Width(650).Height(250)); }))) |
Back to Top