Your search did not match any results.

Charts - Customize Points and Labels

This demo shows how you can customize individual points and labels in the Chart component.

Backend API
<script> var highAverage = 77, lowAverage = 58; function customizePoint() { if(this.value > highAverage) { return { color: "#ff7c7c", hoverStyle: { color: "#ff7c7c" } }; } else if(this.value < lowAverage) { return { color: "#8c8cff", hoverStyle: { color: "#8c8cff" } }; } } function customizeLabel() { if(this.value > highAverage) { return { visible: true, backgroundColor: "#ff7c7c", customizeText: function () { return this.valueText + "&#176F"; } }; } } </script> @(Html.DevExtreme().Chart() .ID("chart") .CommonSeriesSettings(s => s .ArgumentField("Day") .ValueField("Temperature") .Type(SeriesType.Bar) .Color("#e7d19a") ) .CustomizePoint("customizePoint") .CustomizeLabel("customizeLabel") .Export(e => e.Enabled(true)) .ValueAxis(a => a .Add() .VisualRange(range => range.StartValue(40)) .MaxValueMargin(0.01) .Label(l => l.CustomizeText(@<text> function() { return this.valueText + "&#176F"; } </text>)) .ConstantLines(cl => { cl.Add() .Label(l => l.Text("Low Average")) .Width(2) .Value(new JS("lowAverage")) .Color("#8c8cff") .DashStyle(DashStyle.Dash); cl.Add() .Label(l => l.Text("High Average")) .Width(2) .Value(new JS("highAverage")) .Color("#ff7c7c") .DashStyle(DashStyle.Dash); }) ) .Series(s => s.Add()) .Title(t => t.Text("Daily Temperature in May")) .Legend(l => l.Visible(false)) .DataSource(new[] { new { Day = "1", Temperature = 57 }, new { Day = "2", Temperature = 58 }, new { Day = "3", Temperature = 57 }, new { Day = "4", Temperature = 59 }, new { Day = "5", Temperature = 63 }, new { Day = "6", Temperature = 63 }, new { Day = "7", Temperature = 63 }, new { Day = "8", Temperature = 64 }, new { Day = "9", Temperature = 64 }, new { Day = "10", Temperature = 64 }, new { Day = "11", Temperature = 69 }, new { Day = "12", Temperature = 72 }, new { Day = "13", Temperature = 75 }, new { Day = "14", Temperature = 78 }, new { Day = "15", Temperature = 76 }, new { Day = "16", Temperature = 70 }, new { Day = "17", Temperature = 65 }, new { Day = "18", Temperature = 65 }, new { Day = "19", Temperature = 68 }, new { Day = "20", Temperature = 70 }, new { Day = "21", Temperature = 73 }, new { Day = "22", Temperature = 73 }, new { Day = "23", Temperature = 75 }, new { Day = "24", Temperature = 78 }, new { Day = "25", Temperature = 76 }, new { Day = "26", Temperature = 76 }, new { Day = "27", Temperature = 80 }, new { Day = "28", Temperature = 76 }, new { Day = "29", Temperature = 75 }, new { Day = "30", Temperature = 75 }, new { Day = "31", Temperature = 74 } }) )
using DevExtreme.AspNet.Data; using DevExtreme.AspNet.Mvc; using DevExtreme.MVC.Demos.Models.SampleData; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; namespace DevExtreme.MVC.Demos.Controllers { public class ChartsController : Controller { public ActionResult CustomizePointsAndLabels() { return View(); } } }
#chart { height: 440px; }

Customize Points

Use the customizePoint function to change the appearance of individual series points. This function should return an object with properties that you want to change in a point configuration. This demo uses this function to color all points with values above the "High Average" in red, and points with values below the "Low Average" in blue.

Customize Labels

To customize the appearance of individual point labels, implement the customizeLabel function. This function should also return an object with properties that need to be changed for a certain label. This demo specifies custom labels for the red points.

Create Constant Lines

To create constant lines, follow the steps below:

  1. Choose a direction for the line. You can specify horizontal lines in the valueAxis object, and vertical - in the argumentAxis object.

  2. Specify the constantLines object. In this object, declare an object for each line with the properties you want to change.

Note that it's necessary to specify the value property for the line to display correctly.