Example of Inversed Spline in ASP.NET MVC Charts Control
This sample showcases an inversed spline chart depicting stock market capitalization as a percentage of GDP by country, with enhanced interactivity through markers and tooltips.
Stock Market Cap
${x}: ${y}
${x}: ${y}
@Html.UiChart(new UiChartOptions
{
Id = "inversedSplineChart",
Title = "Stock Market Capitalization as a Percentage of GDP by Country",
SubTitle = "Source: wikipedia.org",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, ShowNearestTooltip = true, Template = "#tipInversedSpline" },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}%", Title = "Capitalization Ratio (% of GDP)", ShowGridLines = false, Interval = 40 },
IsTransposed = true,
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Spline, Width = 2, XName = "Country", YName = "Y", Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, IsFilled = true } }
}
})
<template id="tipInversedSpline"><b>Stock Market Cap</b><br>${x}: <b>${y}</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "inversedSplineChart",
Title = "Stock Market Capitalization as a Percentage of GDP by Country",
SubTitle = "Source: wikipedia.org",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, ShowNearestTooltip = true, Template = "#tipInversedSpline" },
PrimaryXAxis = new UiChartAxis { ValueType = UiChartValueType.Category },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}%", Title = "Capitalization Ratio (% of GDP)", ShowGridLines = false, Interval = 40 },
IsTransposed = true,
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Spline, Width = 2, XName = "Country", YName = "Y", Marker = new UiChartMarker { Visible = true, Width = 7, Height = 7, IsFilled = true } }
}
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class ChartController : Controller
{
// The page is Views/Chart/InversedSpline.cshtml; it draws what ViewData holds.
public ActionResult InversedSpline()
{
List<InversedLineChartData> ChartPoints = new List<InversedLineChartData>
{
new InversedLineChartData { Country = "United States", Y = 194.55 },
new InversedLineChartData { Country = "Japan", Y = 146.2 },
new InversedLineChartData { Country = "China", Y = 65.1 },
new InversedLineChartData { Country = "France", Y = 84.9 },
new InversedLineChartData { Country = "India", Y = 140.1 },
new InversedLineChartData { Country = "Canada", Y = 160.7 },
new InversedLineChartData { Country = "Brazil", Y = 68.4 },
new InversedLineChartData { Country = "United Kingdom", Y = 100.2 },
new InversedLineChartData { Country = "Sweden", Y = 162 },
new InversedLineChartData { Country = "Netherlands", Y = 132.3 },
new InversedLineChartData { Country = "Bangladesh", Y = 27.7 }
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class InversedLineChartData
{
public string Country { get; set; }
public double Y { get; set; }
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
@* Charts with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
In this example, you can see how to render and configure inversed spline type charts using the isTransposed property. A spline chart uses a curved line to connect points in a data series. Markers are used to represent individual data points and their values.
Tooltip is enabled in this example. To see the tooltip in action, hover over or tap on the chart.