Tooltip in ASP.NET MVC 3D Chart Component
9 Jan 202413 minutes to read
The 3D Chart will display details about the points through tooltip, when the mouse is moved over the specific point.
Default tooltip
By default, tooltip is not visible. The tooltip can be enabled by setting the Enable
property in TooltipSettings
to true.
@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).
XName("month").
YName("sales").
DataSource(ViewBag.dataSource).
Add();
})
.PrimaryXAxis(px =>
px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
.LabelPlacement(Syncfusion.EJ2.Charts.LabelPlacement.BetweenTicks).LabelRotation(-45)
)
.Tooltip(tp => tp.Enable(true))
.Render())
public ActionResult Index()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { month= "Jan", sales= 35 },
new ChartData { month= "Feb", sales= 28 },
new ChartData { month= "Mar", sales= 34 },
new ChartData { month= "Apr", sales= 32 },
new ChartData { month= "May", sales= 40 },
new ChartData { month= "Jun", sales= 32 },
new ChartData { month= "Jul", sales= 35 },
new ChartData { month= "Aug", sales= 55 },
new ChartData { month= "Sep", sales= 38 },
new ChartData { month= "Oct", sales= 30 },
new ChartData { month= "Nov", sales= 25 },
new ChartData { month= "Dec", sales= 32 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string month;
public double sales;
}
Fixed tooltip
By default, tooltip track the mouse movement, but the tooltip can be set in fixed position by using the Location
property.
@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).
XName("month").
YName("sales").
DataSource(ViewBag.dataSource).
Add();
})
.PrimaryXAxis(px =>
px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
.LabelPlacement(Syncfusion.EJ2.Charts.LabelPlacement.BetweenTicks).LabelRotation(-45)
)
.Tooltip(tp => tp.Enable(true).Location(lc => lc.X(120).Y(20)))
.Render())
public ActionResult Index()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { month= "Jan", sales= 35 },
new ChartData { month= "Feb", sales= 28 },
new ChartData { month= "Mar", sales= 34 },
new ChartData { month= "Apr", sales= 32 },
new ChartData { month= "May", sales= 40 },
new ChartData { month= "Jun", sales= 32 },
new ChartData { month= "Jul", sales= 35 },
new ChartData { month= "Aug", sales= 55 },
new ChartData { month= "Sep", sales= 38 },
new ChartData { month= "Oct", sales= 30 },
new ChartData { month= "Nov", sales= 25 },
new ChartData { month= "Dec", sales= 32 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string month;
public double sales;
}
Format the tooltip
By default, tooltip shows information of x and y value in points. In addition to that, more information can be shown in tooltip by using the Format
property. For example the format ${series.name} : ${point.y}
shows series name and point y value.
@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).
XName("month").
YName("sales").
Name("Month").
DataSource(ViewBag.dataSource).
Add();
})
.PrimaryXAxis(px =>
px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
.LabelPlacement(Syncfusion.EJ2.Charts.LabelPlacement.BetweenTicks).LabelRotation(-45)
)
.Tooltip(tp => tp.Enable(true).Header("Unemployment").Format("<b>${series.name} : ${point.y}</b>"))
.Render())
public ActionResult Index()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { month= "Jan", sales= 35 },
new ChartData { month= "Feb", sales= 28 },
new ChartData { month= "Mar", sales= 34 },
new ChartData { month= "Apr", sales= 32 },
new ChartData { month= "May", sales= 40 },
new ChartData { month= "Jun", sales= 32 },
new ChartData { month= "Jul", sales= 35 },
new ChartData { month= "Aug", sales= 55 },
new ChartData { month= "Sep", sales= 38 },
new ChartData { month= "Oct", sales= 30 },
new ChartData { month= "Nov", sales= 25 },
new ChartData { month= "Dec", sales= 32 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string month;
public double sales;
}
Tooltip template
Any HTML elements can be displayed in the tooltip by using the Template
property of the tooltip. The ${x} and ${y} can be used as place holders in the HTML element to display the x and y values of the corresponding data point.
@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).
XName("month").
YName("sales").
DataSource(ViewBag.dataSource).
Add();
})
.PrimaryXAxis(px =>
px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
.LabelPlacement(Syncfusion.EJ2.Charts.LabelPlacement.BetweenTicks).LabelRotation(-45)
)
.Tooltip(tp => tp.Enable(true).Template("#Unemployment"))
.Render())
public ActionResult Index()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { month= "Jan", sales= 35 },
new ChartData { month= "Feb", sales= 28 },
new ChartData { month= "Mar", sales= 34 },
new ChartData { month= "Apr", sales= 32 },
new ChartData { month= "May", sales= 40 },
new ChartData { month= "Jun", sales= 32 },
new ChartData { month= "Jul", sales= 35 },
new ChartData { month= "Aug", sales= 55 },
new ChartData { month= "Sep", sales= 38 },
new ChartData { month= "Oct", sales= 30 },
new ChartData { month= "Nov", sales= 25 },
new ChartData { month= "Dec", sales= 32 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string month;
public double sales;
}
Customize the appearance of tooltip
The Fill
and Border
properties are used to customize the background color and border of the tooltip respectively. The TextStyle
property in the tooltip is used to customize the font of the tooltip text.
@(Html.EJS().Chart3D("container").WallColor("transparent").EnableRotation(true).Rotation(7).Tilt(10).Depth(100)
.Series(series =>
{
series.Type(Syncfusion.EJ2.Charts.Chart3DSeriesType.Column).
XName("month").
YName("sales").
Name("China").
DataSource(ViewBag.dataSource).
Add();
})
.PrimaryXAxis(px =>
px.ValueType(Syncfusion.EJ2.Charts.ValueType.Category)
.LabelPlacement(Syncfusion.EJ2.Charts.LabelPlacement.BetweenTicks).LabelRotation(-45)
)
.Tooltip(tp => tp.Enable(true).Format("${point.x} : ${point.y}").Fill("#7bb4eb")
.Border(br => br.Width(2).Color("grey")))
.Render())
public ActionResult Index()
{
List<ChartData> chartData = new List<ChartData>
{
new ChartData { month= "Jan", sales= 35 },
new ChartData { month= "Feb", sales= 28 },
new ChartData { month= "Mar", sales= 34 },
new ChartData { month= "Apr", sales= 32 },
new ChartData { month= "May", sales= 40 },
new ChartData { month= "Jun", sales= 32 },
new ChartData { month= "Jul", sales= 35 },
new ChartData { month= "Aug", sales= 55 },
new ChartData { month= "Sep", sales= 38 },
new ChartData { month= "Oct", sales= 30 },
new ChartData { month= "Nov", sales= 25 },
new ChartData { month= "Dec", sales= 32 }
};
ViewBag.dataSource = chartData;
return View();
}
public class ChartData
{
public string month;
public double sales;
}