Your search did not match any results.

Charts - Custom Annotations

Annotations are designed to show additional information about visualized data. You can display images, text blocks, and custom content in annotations. To create custom annotations, specify the following Chart properties.

en.wikipedia.org
Backend API
@{ var dataSource = new[] { new { Name = "California", Population = 38802500, Capital = "Sacramento", Area = 423967 }, new { Name = "Texas", Population = 26956958, Capital = "Austin", Area = 695662 }, new { Name = "Florida", Population = 19893297, Capital = "Tallahassee", Area = 170312 }, new { Name = "New York", Population = 19746227, Capital = "Albany", Area = 141297 }, new { Name = "Illinois", Population = 12880580, Capital = "Springfield", Area = 149995 } }; } @(Html.DevExtreme().Chart() .ID("chart") .Title("Top 5 Most Populated States in US") .Series(s => s .Add() .Type(SeriesType.Bar) .ArgumentField("Name") .ValueField("Population") .Name("Population") ) .CommonAnnotationSettings(c=>c.Series("Population") .Type(AnnotationType.Custom) .AllowDragging(true) .Template(@<text> <svg class='annotation'> <image href="<%-getImagePath(argument)%>" width="60" height="40" /> <rect class="border" x="0" y="0" /> <text x="70" y="25" class="state"><%- argument %></text> <text x="0" y="60"> <tspan class="caption">Capital:</tspan><tspan class="capital" dx="5"><%- data.Capital %></tspan><tspan dy="14" x="0" class="caption">Population:</tspan><tspan class="population" dx="5"><%- formatNumber(data.Population) %></tspan><tspan dy="14" x="0" class="caption">Area:</tspan><tspan class="area" dx="5"><%- formatNumber(data.Area) %></tspan><tspan dx="5">km</tspan><tspan class="sup" dy="-2">2</tspan> </text> </svg> </text>)) .Annotations(a => { foreach(var dataItem in dataSource) { a.Add().Argument(dataItem.Name) .Data(dataItem); } }) .Legend(l=>l.Visible(false)) .DataSource(dataSource) ) <script> var formatNumber = new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format; function getImagePath(argument) { return '../../images/flags/' + argument.replace(/\s/, "") + ".svg"; } </script>
using DevExtreme.AspNet.Data; using DevExtreme.AspNet.Mvc; using DevExtreme.NETCore.Demos.Models; using DevExtreme.NETCore.Demos.Models.SampleData; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; namespace DevExtreme.NETCore.Demos.Controllers { public class ChartsController : Controller { public ActionResult CustomAnnotations() { return View(); } } }
#chart { height: 440px; } .annotation { font-size: 12px; } .border { width: 60px; height: 40px; stroke: rgba(191, 191, 191, 0.25); stroke-width: 1px; fill: transparent; } .state { font-weight: 500; font-size: 14px; } .caption { font-weight: 500; } .sup { font-size: 0.8em; }

annotations[]

The annotations array specifies a collection of annotations. This demo uses a data source array to create this collection. Each object has the argument property and a data object. The argument property positions an annotation at a specific argument, and the data object stores data from a data source.

You can use the annotations array to configure each annotation individually.

commonAnnotationSettings

Use the commonAnnotationSettings object to specify settings common to all annotations in the chart. In this object, assign custom to the type property. To anchor annotations to a series point, specify the series property. Finally, declare the SVG markup in the annotation template.

Note that individual annotation settings override the common annotation settings.

customizeAnnotation

You can also implement the customizeAnnotation function to customize an individual chart annotation.