Component One ASP.Net MVC

ASP.Net MVC FlexPie 101

This page shows how to get started with ASP.Net MVC's FlexPie control.

Getting Started

Steps for getting started with the FlexPie control in MVC applications:

  1. Create a new MVC project using the C1 ASP.NET MVC application template.
  2. Add controller and corresponding view to the project.
  3. Initialize the FlexPie control in view using razor syntax.
  4. (Optional) Add some CSS to customize the FlexPie control's appearance.
<!DOCTYPE html> <html> <head> @Html.C1().Resources(typeof(C1Chart)) </head> <body> @using C1.Web.Mvc <!-- FlexPie --> @(Html.C1().FlexPie().Id("introChart").Header("Products Sale By Country") .Bind("Country", "Count", Model.CountryGroupOrderData).DataLabel(dl => dl.Content("{value}"))) </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using C1.Web.Mvc; using C1.Web.Mvc.Chart; using ASPNetMVCFlexPie101.Models; namespace ASPNetMVCFlexPie101.Controllers { public class HomeController : Controller { public ActionResult Index() { FlexPieModel ModelObj = new FlexPieModel(); ModelObj.CountryGroupOrderData = CustomerOrder.GetCountryGroupOrderData(); return View(ModelObj); } } }

Result (live):

Basic Features

The FlexPie control has five basic properties that allow you to customize its layout and appearance:

The example below allows you to see what happens when you change these properties. Also, clicking on a pie slice will display a tooltip for the data point.

@(Html.C1().FlexPie().Id("basicChart").Header("Products Sale By Country") .Bind("Country", "Count", Model.CountryGroupOrderData) .DataLabel(dl => dl.Content("{value}")) ) <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Inner Radius</label> <div class="col-md-9"> @(Html.C1().InputNumber().Id("basicInnerRadius").Min(0).Max(1).Step(.1) .Format("n").OnClientValueChanged("basicInnerRadius_valueChanged") ) </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Offset</label> <div class="col-md-9"> @(Html.C1().InputNumber().Id("basicOffset").Min(0).Max(1).Step(.1) .Format("n").OnClientValueChanged("basicOffset_valueChanged") ) </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Start Angle</label> <div class="col-md-9"> @(Html.C1().InputNumber().Id("basicStartAngle").Min(-360).Max(360).Step(45) .Format("n").OnClientValueChanged("basicStartAngle_valueChanged") ) </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> @(Html.C1().ComboBox().Id("basicPalette").Bind(Model.Settings["Palette"]) .Placeholder("Pallete").SelectedValue("standard") .OnClientSelectedIndexChanged("basicPalette_SelectedIndexChanged") ) </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <div class="checkbox"> <label> <input id="basicReversed" type="checkbox" /> Reversed? </label> </div> </div> </div> </div>
$(document).ready(function () { //Basic Features Module var basicReversed = document.getElementById('basicReversed'); basicReversed.addEventListener('change', function () { // determine reversed by checkbox's checked state var chart = wijmo.Control.getControl("#basicChart"); chart.reversed = this.checked; }); }); //Basic Features Module function basicInnerRadius_valueChanged(sender) { var chart = wijmo.Control.getControl("#basicChart"); chart.innerRadius = sender.value; }; function basicOffset_valueChanged(sender) { var chart = wijmo.Control.getControl("#basicChart"); chart.offset = sender.value; }; function basicStartAngle_valueChanged(sender) { var chart = wijmo.Control.getControl("#basicChart"); chart.startAngle = sender.value; }; function basicPalette_SelectedIndexChanged(sender) { if (!sender.selectedValue) return; var chart = wijmo.Control.getControl("#basicChart"); chart.palette = wijmo.chart.Palettes[sender.selectedValue]; };
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using C1.Web.Mvc; using C1.Web.Mvc.Chart; using ASPNetMVCFlexPie101.Models; namespace ASPNetMVCFlexPie101.Controllers { public class HomeController : Controller { public ActionResult Index() { FlexPieModal ModelObj = new FlexPieModal(); ModelObj.Settings = CreateSettings(); ModelObj.CountryGroupOrderData = CustomerOrder.GetCountryGroupOrderData(); return View(ModelObj); } private static IDictionary<string, object[]> CreateSettings() { var settings = new Dictionary<string, object[]> { {"Palette", new object[]{"standard", "cocoa", "coral", "dark", "highcontrast", "light", "midnight", "minimal", "modern", "organic", "slate"}}, {"LegendPosition", new object[]{Position.Top.ToString(), Position.Bottom.ToString(), Position.Left.ToString(), Position.None.ToString(), Position.Right.ToString()}}, {"SelectedItemPosition", new object[]{Position.Top.ToString(), Position.Bottom.ToString(), Position.Left.ToString(), Position.None.ToString(), Position.Right.ToString()}}, }; return settings; } } }

Result (live):

Legend & Titles

The Legend properties can be used to customize the appearance of the chart's legend. The Header and Footer properties can be used to add titles to the FlexPie control as well.

The following example allows you to change the FlexPie's Legend, Header, and Footer properties in real-time.

@(Html.C1().FlexPie().Id("ltChart").Header("Products Sale By Country") .Bind("Country", "Count", Model.CountryGroupOrderData) .DataLabel(dl => dl.Content("{value}")) ) <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Header</label> <div class="col-md-9"> <input id="ltHeader" type="text" class="form-control" placeholder="Specify the FlexPie's header" /> </div> </div> <div class="form-group"> <label class="col-md-3 control-label">Footer</label> <div class="col-md-9"> <input id="ltFooter" type="text" class="form-control" placeholder="Specify the FlexPie's footer" /> </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> @(Html.C1().ComboBox().Id("ltLegPos").Bind(Model.Settings["LegendPosition"]) .Placeholder("Legend Position").SelectedValue("Right") .OnClientSelectedIndexChanged("ltLegPos_SelectedIndexChanged") ) </div> </div>
$(document).ready(function () { //Legend & Title Module var ltchart = wijmo.Control.getControl("#ltChart"); var ltHeader = document.getElementById('ltHeader'); var ltFooter = document.getElementById('ltFooter'); ltHeader.value = ltchart.header = 'Products By Country'; ltFooter.value = ltchart.footer = '2014, GrapeCity Inc.'; ltHeader.addEventListener('input', function () { ltchart.header = this.value; }); ltFooter.addEventListener('input', function () { ltchart.footer = this.value; }); }); //Legend & Title Module function ltLegPos_SelectedIndexChanged(sender) { if (!sender.selectedValue) return; var chart = wijmo.Control.getControl("#ltChart"); chart.legend.position = sender.selectedValue; };
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using C1.Web.Mvc; using C1.Web.Mvc.Chart; using ASPNetMVCFlexPie101.Models; namespace ASPNetMVCFlexPie101.Controllers { public class HomeController : Controller { public ActionResult Index() { FlexPieModal ModelObj = new FlexPieModal(); ModelObj.Settings = CreateSettings(); ModelObj.CountryGroupOrderData = CustomerOrder.GetCountryGroupOrderData(); return View(ModelObj); } private static IDictionary<string, object[]> CreateSettings() { var settings = new Dictionary<string, object[]> { {"Palette", new object[]{"standard", "cocoa", "coral", "dark", "highcontrast", "light", "midnight", "minimal", "modern", "organic", "slate"}}, {"LegendPosition", new object[]{Position.Top.ToString(), Position.Bottom.ToString(), Position.Left.ToString(), Position.None.ToString(), Position.Right.ToString()}}, {"SelectedItemPosition", new object[]{Position.Top.ToString(), Position.Bottom.ToString(), Position.Left.ToString(), Position.None.ToString(), Position.Right.ToString()}}, }; return settings; } } }

Result (live):

Selection

The FlexPie control allows you to select data points by clicking or touching a pie slice. Use the SelectionMode property to specify whether you want to allow selection by data point or no selection at all (default).

Setting the SelctionMode property to Point causes the FlexPie to update the Selection property when the user clicks on a pie slice, and to apply the "wj-state-selected" class to the selected element. Setting the FlexPie's SelectionMode property to Series or None will disable selections within the control.

The FlexPie offers three additional properties to customize the selection:

@(Html.C1().FlexPie().Id("selChart").Header("Products Sale By Country") .Bind("Country", "Count", Model.CountryGroupOrderData).IsAnimated(true) .SelectionMode(C1.Web.Mvc.Chart.SelectionMode.Point) .SelectedItemPosition(C1.Web.Mvc.Chart.Position.Top).DataLabel(dl => dl.Content("{value}")) ) <div class="form-horizontal"> <div class="form-group"> <label class="col-md-3 control-label">Selected Item Offset</label> <div class="col-md-9"> @(Html.C1().InputNumber().Id("selItemOffset").Min(0).Max(.5).Step(.1) .Format("n").OnClientValueChanged("selItemOffset_valueChanged") ) </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> @(Html.C1().ComboBox().Id("selItemPos").Bind(Model.Settings["SelectedItemPosition"]) .Placeholder("Selected Item Position").SelectedValue("Top") .OnClientSelectedIndexChanged("selItemPos_SelectedIndexChanged") ) </div> </div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <div class="checkbox"> <label> <input id="selAnimated" type="checkbox"> Is Animated? </label> </div> </div> </div> </div>
$(document).ready(function () { //Selection Module var selAnimated = document.getElementById('selAnimated'); selAnimated.checked = true; selAnimated.addEventListener('change', function () { // determine Is Animated by checkbox's checked state var chart = wijmo.Control.getControl("#selChart"); chart.isAnimated = this.checked; }); }); //Selection Module function selItemOffset_valueChanged(sender) { var chart = wijmo.Control.getControl("#selChart"); chart.selectedItemOffset = sender.value; }; function selItemPos_SelectedIndexChanged(sender) { if (!sender.selectedValue) return; var chart = wijmo.Control.getControl("#selChart"); chart.selectedItemPosition = sender.selectedValue; };
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using C1.Web.Mvc; using C1.Web.Mvc.Chart; using ASPNetMVCFlexPie101.Models; namespace ASPNetMVCFlexPie101.Controllers { public class HomeController : Controller { public ActionResult Index() { FlexPieModal ModelObj = new FlexPieModal(); ModelObj.Settings = CreateSettings(); ModelObj.CountryGroupOrderData = CustomerOrder.GetCountryGroupOrderData(); return View(ModelObj); } private static IDictionary<string, object[]> CreateSettings() { var settings = new Dictionary<string, object[]> { {"Palette", new object[]{"standard", "cocoa", "coral", "dark", "highcontrast", "light", "midnight", "minimal", "modern", "organic", "slate"}}, {"LegendPosition", new object[]{Position.Top.ToString(), Position.Bottom.ToString(), Position.Left.ToString(), Position.None.ToString(), Position.Right.ToString()}}, {"SelectedItemPosition", new object[]{Position.Top.ToString(), Position.Bottom.ToString(), Position.Left.ToString(), Position.None.ToString(), Position.Right.ToString()}}, }; return settings; } } }

Result (live):

Theming

The appearance of the FlexPie control is largely defined in CSS. In addition to the default theme, we include several professionally designed themes that customize the appearance of all MVC controls to achieve a consistent, attractive look.

You can customize the appearance of the FlexPie control using CSS. To do this, copy the CSS rules from the default theme to a new CSS file and modify the properties as needed.

In this example, we added the "custom-pie-chart" CSS class to the control and defined some CSS rules to change the fill, font family, and font weight of the header, footer, and legend.

@(Html.C1().FlexPie().Id("themeChart").Header("Products Sale By Country").CssClass("custom-pie-chart") .Bind("Country", "Count", Model.CountryGroupOrderData).IsAnimated(true) .SelectionMode(C1.Web.Mvc.Chart.SelectionMode.Point) .SelectedItemPosition(C1.Web.Mvc.Chart.Position.Top).DataLabel(dl => dl.Content("{value}")) )
.custom-pie-chart.wj-flexchart .wj-header .wj-title, .custom-pie-chart.wj-flexchart .wj-footer .wj-title, .custom-pie-chart.wj-flexchart .wj-legend > .wj-label { fill: #666; font-family: 'Courier New', Courier, monospace; font-weight: bold; }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using C1.Web.Mvc; using C1.Web.Mvc.Chart; using ASPNetMVCFlexPie101.Models; namespace ASPNetMVCFlexPie101.Controllers { public class HomeController : Controller { public ActionResult Index() { FlexPieModal ModelObj = new FlexPieModal(); ModelObj.Settings = CreateSettings(); ModelObj.CountryGroupOrderData = CustomerOrder.GetCountryGroupOrderData(); return View(ModelObj); } private static IDictionary<string, object[]> CreateSettings() { var settings = new Dictionary<string, object[]> { {"Palette", new object[]{"standard", "cocoa", "coral", "dark", "highcontrast", "light", "midnight", "minimal", "modern", "organic", "slate"}}, {"LegendPosition", new object[]{Position.Top.ToString(), Position.Bottom.ToString(), Position.Left.ToString(), Position.None.ToString(), Position.Right.ToString()}}, {"SelectedItemPosition", new object[]{Position.Top.ToString(), Position.Bottom.ToString(), Position.Left.ToString(), Position.None.ToString(), Position.Right.ToString()}}, }; return settings; } } }

Result (live):