This demo illustrates the use of the pointClick callback function to implement selection in the Chart component. The selectionMode of the series is set to «allArgumentPoints», which means that when a user selects a point, other points with the same argument also become selected.
@(Html.DevExtreme().Chart()
.ID("chart")
.Rotated(true)
.CommonSeriesSettings(s => s
.ArgumentField("Country")
.Type(SeriesType.Bar)
.HoverMode(ChartSeriesHoverMode.AllArgumentPoints)
.SelectionMode(ChartSeriesSelectionMode.AllArgumentPoints)
.Label(l => l
.Visible(true)
.Format(f => f.Type(Format.Percent).Precision(1))
)
)
.ValueAxis(a => a.Add().Label(l => l.Format(f => f.Type(Format.Percent).Precision(1))))
.Series(s => {
s.Add().ValueField("Year2019").Name("2019 - 2020");
s.Add().ValueField("Year2020").Name("2020 - 2021");
})
.Title(t => t.Text("Economy - Export Change"))
.Legend(l => l
.VerticalAlignment(VerticalEdge.Bottom)
.HorizontalAlignment(HorizontalAlignment.Center)
)
.Export(e => e.Enabled(true))
.OnPointClick(@<text>
function(e) {
e.target.select();
}
</text>)
.OnLegendClick(@<text>
function(e) {
var series = e.target;
if(series.isVisible()) {
series.hide();
} else {
series.show();
}
}
</text>)
.DataSource(new[] {
new { Country = "United Kingdom", Year2019 = 0.142, Year2020 = -0.153 },
new { Country = "Germany", Year2019 = 0.109, Year2020 = -0.120 },
new { Country = "United States", Year2019 = 0.097, Year2020 = -0.134 },
new { Country = "Japan", Year2019 = 0.106, Year2020 = -0.111 },
new { Country = "France", Year2019 = 0.113, Year2020 = -0.162 },
new { Country = "Netherlands", Year2019 = 0.128, Year2020 = -0.147 }
})
)
using DevExtreme.AspNet.Data;
using DevExtreme.AspNet.Mvc;
using DevExtreme.MVC.Demos.Models.SampleData;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Web.Mvc;
namespace DevExtreme.MVC.Demos.Controllers {
public class ChartsController : Controller {
public ActionResult Selection() {
return View();
}
}
}
#chart {
height: 440px;
}