- Tooltip for axis
- Customization
- Trackball
- Crosshair highlight
Contact Support
Crosshair in ASP.NET MVC Chart Component
8 Apr 202513 minutes to read
Crosshair has a vertical and horizontal line to view the value of the axis at mouse or touch position.
Crosshair lines can be enabled by using Enable
property in the Crosshair
.
@Html.EJS().Chart("container").
ChartArea(area => area.Border(ViewBag.ChartBorder))
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).Width(2).XName("xValue").Marker(ViewBag.marker).YName("yValue").DataSource(ViewBag.dataSource).Name("Germany").Add();
})
.PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
.IntervalType(Syncfusion.EJ2.Charts.IntervalType.Years)
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift).LabelFormat("y"))
.PrimaryYAxis(py => py.LabelFormat("{value}%")
.RangePadding(Syncfusion.EJ2.Charts.ChartRangePadding.None)
.Interval(20).Minimum(0).Maximum(100))
.Title("Inflation - Consumer Price")
.Tooltip(tt => tt.Enable(true))
.Crosshair(cr=>cr.Enable(true)).Render()
public ActionResult Index()
{
return View();
}
Tooltip for axis
Tooltip label for an axis can be enabled by using Enable
property of CrosshairTooltip
in the corresponding axis.
@Html.EJS().Chart("container").
ChartArea(area => area.Border(ViewBag.ChartBorder))
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).Width(2).XName("xValue").Marker(ViewBag.marker).YName("yValue").DataSource(ViewBag.dataSource).Name("Germany").Add();
})
.PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
.IntervalType(Syncfusion.EJ2.Charts.IntervalType.Years)
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift).LabelFormat("y")
.CrosshairTooltip(ViewBag.cross))
.PrimaryYAxis(py => py.LabelFormat("{value}%")
.RangePadding(Syncfusion.EJ2.Charts.ChartRangePadding.None)
.Interval(20).Minimum(0).Maximum(100)
.CrosshairTooltip(ViewBag.cross))
.Title("Inflation - Consumer Price")
.Tooltip(tt => tt.Enable(true))
.Crosshair(cr=>cr.Enable(true)).Render()
public ActionResult Index()
{
return View();
}
Customization
The Fill
and TextStyle
property of the CrosshairTooltip
is used to customize the background color and font style of the crosshair label respectively. Color and width of the crosshair line can be customized by using the Line
property in the crosshair.
@Html.EJS().Chart("container").
ChartArea(area => area.Border(ViewBag.ChartBorder))
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).Width(2).XName("xValue").Marker(ViewBag.marker).YName("yValue").DataSource(ViewBag.dataSource).Name("Germany").Add();
})
.PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
.IntervalType(Syncfusion.EJ2.Charts.IntervalType.Years)
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift).LabelFormat("y")
.CrosshairTooltip(ViewBag.cross))
.PrimaryYAxis(py => py.LabelFormat("{value}%")
.RangePadding(Syncfusion.EJ2.Charts.ChartRangePadding.None)
.Interval(20).Minimum(0).Maximum(100)
.CrosshairTooltip(ViewBag.cross))
.Title("Inflation - Consumer Price")
.Tooltip(tt => tt.Enable(true))
.Crosshair(ViewBag.CrossLine).Render()
public ActionResult Index()
{
return View();
}
Snap to data
Enabling the SnapToData
property in the crosshair aligns it with the nearest data point instead of following the exact mouse position.
@Html.EJS().Chart("container").
ChartArea(area => area.Border(ViewBag.ChartBorder))
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).Width(2).XName("xValue").Marker(ViewBag.marker).YName("yValue").DataSource(ViewBag.dataSource).Name("Germany").Add();
})
.PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
.IntervalType(Syncfusion.EJ2.Charts.IntervalType.Years)
.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift).LabelFormat("y")
.CrosshairTooltip(ViewBag.cross))
.PrimaryYAxis(py => py.LabelFormat("{value}%")
.RangePadding(Syncfusion.EJ2.Charts.ChartRangePadding.None)
.Interval(20).Minimum(0).Maximum(100)
.CrosshairTooltip(ViewBag.cross))
.Title("Inflation - Consumer Price")
.Tooltip(tt => tt.Enable(true))
.Crosshair(cross => cross.Enable(true).LineType("Horizontal").SnapToData(true)).Render()
public ActionResult Index()
{
return View();
}
Trackball
Trackball is used to track a data point closest to the mouse or touch position. Trackball marker indicates the closest point and trackball tooltip displays the information about the point.
Trackball can be enabled by setting the Enable
property of the crosshair to true and Shared
property in Tooltip
to true in chart.
@Html.EJS().Chart("container-vertical").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).XName("x").YName("yValue").Marker(ViewBag.marker)
.DataSource(ViewBag.dataSource ).Name("John").Width(2).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).XName("x").YName("yValue1").Marker(ViewBag.marker)
.DataSource(ViewBag.dataSource ).Name("Andrew").Width(2).Add();
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).XName("x").YName("yValue2").Marker(ViewBag.marker)
.DataSource(ViewBag.dataSource).Name("Thomas").Width(2).Add();})\
.PrimaryXAxis(px => px.EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift)
.MajorGridLines(ViewBag.majorGridLines).LineStyle(ViewBag.lineStyle)
.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)
.Skeleton("y"))
.PrimaryYAxis(py => py.Title("Revenue")
.MajorTickLines(ViewBag.majorTickLines)
.LineStyle(ViewBag.lineStyle)
.Minimum(10)
.Maximum(80)
.LabelFormat("{value}M"))
.ChartArea(area => area.Border(ViewBag.ChartBorder))
.Tooltip(tl =>tl.Enable(true).Shared(true))
.Crosshair(cr => cr.Enable(true).LineType(Syncfusion.EJ2.Charts.LineType.Vertical))
.Title("Average Sales per Person").Render()
public ActionResult Index()
{
List<TrackballChartData> chartData = new List<TrackballChartData>
{
new TrackballChartData { xValue = new DateTime(2000, 2, 11), yValue = 14, yValue1 = 39, yValue2 = 60 },
new TrackballChartData { xValue = new DateTime(2000, 9, 4), yValue = 20, yValue1 = 30, yValue2 = 55 },
new TrackballChartData { xValue = new DateTime(2001, 2, 11), yValue = 25, yValue1 = 28, yValue2 = 48 },
new TrackballChartData { xValue = new DateTime(2001, 9, 16), yValue = 21, yValue1 = 35, yValue2 = 57 },
new TrackballChartData { xValue = new DateTime(2002, 2, 7), yValue = 13, yValue1 = 39, yValue2 = 62 },
new TrackballChartData { xValue = new DateTime(2002, 9, 7), yValue = 18, yValue1 = 41, yValue2 = 64 },
new TrackballChartData { xValue = new DateTime(2003, 2, 11), yValue = 24, yValue1 = 45, yValue2 = 57 },
new TrackballChartData { xValue = new DateTime(2003, 9, 14), yValue = 23, yValue1 = 48, yValue2 = 53 },
new TrackballChartData { xValue = new DateTime(2004, 2, 6), yValue = 19, yValue1 = 54, yValue2 = 63 },
new TrackballChartData { xValue = new DateTime(2004, 9, 6), yValue = 31, yValue1 = 55, yValue2 = 50 },
new TrackballChartData { xValue = new DateTime(2005, 2, 11), yValue = 39, yValue1 = 57, yValue2 = 66 },
new TrackballChartData { xValue = new DateTime(2005, 9, 11), yValue = 50, yValue1 = 60, yValue2 = 65 },
new TrackballChartData { xValue = new DateTime(2006, 2, 11), yValue = 24, yValue1 = 60, yValue2 = 79 },
};
ViewBag.dataSource = chartData;
return View();
}
public class TrackballChartData
{
public DateTime xValue;
public double yValue;
public double yValue1;
public double yValue2;
}
Crosshair highlight
The HighlightCategory
property in the crosshair highlights the background of the entire category when hovered over. The crosshair color can be customized using the Color
property within the Line
configuration.
@Html.EJS().Chart("container").Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Column)
.XName("Country")
.YName("Gold")
.DataSource(ViewBag.dataSource)
.Add();
}
).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
).Crosshair(cr=>cr.Enable(true).Line(l=>l.Color("red")).LineType(Syncfusion.EJ2.Charts.LineType.Vertical).HighlightCategory(true)).Render()
public ActionResult Index()
{
List<HighLightCategoryData> chartData = new List<HighLightCategoryData>
{
new HighLightCategoryData { Country = "USA", Gold = 50 },
new HighLightCategoryData { Country = "China", Gold = 40 },
new HighLightCategoryData { Country = "Japan", Gold = 70 },
new HighLightCategoryData { Country = "Australia", Gold = 60 },
new HighLightCategoryData { Country = "France", Gold = 50 },
new HighLightCategoryData { Country = "Germany", Gold = 40 },
new HighLightCategoryData { Country = "Italy", Gold = 40 },
new HighLightCategoryData { Country = "Sweden", Gold = 30 }
};
ViewBag.dataSource = chartData;
return View();
}
public class HighLightCategoryData
{
public string Country;
public double Gold;
}