Example of Marker Chart in ASP.NET MVC Charts Control
This sample illustrates Facebook users in a chart for different countries over several years. In a line-based series, data points can be annotated using symbols.
${x}
${series} : ${y}
${series} : ${y}
@Html.UiChart(new UiChartOptions
{
Id = "markerChart",
Title = "FB Penetration of Internet Audience",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, ShowNearestTooltip = true, Template = "#tipMarkers" },
Legend = new UiChartLegend { Visible = true, EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { Interval = 1, ShowGridLines = false, ValueType = UiChartValueType.Category },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}%", Minimum = 0, Maximum = 75, Interval = 15 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "Country", YName = "FBUser_07", Name = "2007", Opacity = 1, Marker = new UiChartMarker { Visible = true, Height = 8, Width = 8, IsFilled = true, Shape = UiChartMarkerShape.Diamond } },
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "Country", YName = "FBUser_08", Name = "2008", Opacity = 1, Marker = new UiChartMarker { Visible = true, Height = 8, Width = 8, IsFilled = true, Shape = UiChartMarkerShape.Pentagon } },
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "Country", YName = "FBUser_09", Name = "2009", Opacity = 1, Marker = new UiChartMarker { Visible = true, Height = 8, Width = 8, IsFilled = true, Shape = UiChartMarkerShape.Triangle } }
}
})
<template id="tipMarkers"><b>${x}</b> <br> ${series} : <b>${y}</b></template>
@Html.UiChart(new UiChartOptions
{
Id = "markerChart",
Title = "FB Penetration of Internet Audience",
Data = (IEnumerable<object>)ViewData["ChartPoints"],
Tooltip = new UiChartTooltip { Enable = true, EnableHighlight = true, ShowNearestTooltip = true, Template = "#tipMarkers" },
Legend = new UiChartLegend { Visible = true, EnableHighlight = true },
PrimaryXAxis = new UiChartAxis { Interval = 1, ShowGridLines = false, ValueType = UiChartValueType.Category },
PrimaryYAxis = new UiChartAxis { LabelFormat = "{value}%", Minimum = 0, Maximum = 75, Interval = 15 },
Series = new List<UiChartSeries>
{
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "Country", YName = "FBUser_07", Name = "2007", Opacity = 1, Marker = new UiChartMarker { Visible = true, Height = 8, Width = 8, IsFilled = true, Shape = UiChartMarkerShape.Diamond } },
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "Country", YName = "FBUser_08", Name = "2008", Opacity = 1, Marker = new UiChartMarker { Visible = true, Height = 8, Width = 8, IsFilled = true, Shape = UiChartMarkerShape.Pentagon } },
new UiChartSeries { Type = UiChartSeriesType.Line, Width = 2, XName = "Country", YName = "FBUser_09", Name = "2009", Opacity = 1, Marker = new UiChartMarker { Visible = true, Height = 8, Width = 8, IsFilled = true, Shape = UiChartMarkerShape.Triangle } }
}
})
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/Markers.cshtml; it draws what ViewData holds.
public ActionResult Markers()
{
List<SymbolsData> ChartPoints = new List<SymbolsData>
{
new SymbolsData { Country = "World Wide", FBUser_07 = 12, FBUser_08 = 22, FBUser_09 = 38.3, TooltipMappingName = "World Wide"},
new SymbolsData { Country = "Europe", FBUser_07 = 9.9, FBUser_08 = 26, FBUser_09 = 45.2, TooltipMappingName = "Europe" },
new SymbolsData { Country = "Asia Pacific", FBUser_07 = 6.4, FBUser_08 = 9.6, FBUser_09 = 18.2, TooltipMappingName = "Asia Pacific"},
new SymbolsData { Country = "Latin America", FBUser_07 = 4.4, FBUser_08 = 28, FBUser_09 = 46.7, TooltipMappingName = "Latin America"},
new SymbolsData { Country = "Middle East Africa", FBUser_07 = 30, FBUser_08 = 45.7, FBUser_09 = 61.5, TooltipMappingName = "Middle East Africa"},
new SymbolsData { Country = "North America", FBUser_07 = 25.3, FBUser_08 = 35.9, FBUser_09 = 64, TooltipMappingName = "North America"},
};
ViewData["ChartPoints"] = ChartPoints;
return View();
}
public class SymbolsData
{
public string Country { get; set; }
public double FBUser_07 { get; set; }
public double FBUser_08 { get; set; }
public double FBUser_09 { get; set; }
public string TooltipMappingName { 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. *@
Each data point in a series can be represented by a symbol as a marker. You can customize the shape, size and color of the symbol with the ChartMarker class.
Tooltip is enabled in this example. To see the tooltip in action, hover over a point or tap on a point in touch-enabled devices.