Skip to content

Commit bef2c1c

Browse files
authored
Merge pull request #402 from apexcharts/custom-tooltip-no-eval
Removed the need to run javascript eval for custom tooltip
2 parents 8ee25d0 + 618d10a commit bef2c1c

4 files changed

Lines changed: 26 additions & 13 deletions

File tree

docs/BlazorApexCharts.Docs.Server/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"BlazorApexCharts.Docs.Server": {
1212
"commandName": "Project",
1313
"launchBrowser": true,
14-
"launchUrl": "features/annotations",
14+
"launchUrl": "features/tooltip",
1515
"environmentVariables": {
1616
"ASPNETCORE_ENVIRONMENT": "Development"
1717
},

src/Blazor-ApexCharts/ApexChart.razor.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,17 +1045,7 @@ private void SetCustomTooltip()
10451045
{
10461046
if (ApexPointTooltip == null) { return; }
10471047
if (Options.Tooltip == null) { Options.Tooltip = new Tooltip(); }
1048-
1049-
var customTooltip = @"function({series, seriesIndex, dataPointIndex, w}) {
1050-
var sourceId = 'apex-tooltip-' + w.globals.chartID;
1051-
var source = document.getElementById(sourceId);
1052-
if (source) {
1053-
return source.innerHTML;
1054-
}
1055-
return '...'
1056-
}";
1057-
1058-
Options.Tooltip.Custom = customTooltip;
1048+
Options.Tooltip.CustomTooltip = true;
10591049
}
10601050

10611051
private async Task RenderChartAsync()

src/Blazor-ApexCharts/Models/ApexChartOptions.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class ApexChartOptions<TItem> where TItem : class
9494

9595
/// <inheritdoc cref="ApexCharts.Tooltip" />
9696
public Tooltip Tooltip { get; set; }
97-
97+
9898
/// <inheritdoc cref="ApexCharts.XAxis" />
9999
public XAxis Xaxis { get; set; }
100100

@@ -4128,10 +4128,22 @@ public class TitleStyle
41284128
/// </remarks>
41294129
public class Tooltip
41304130
{
4131+
4132+
/// <summary>
4133+
/// Undocumented
4134+
/// </summary>
41314135
public bool? HideEmptySeries { get; set; }
41324136

4137+
/// <summary>
4138+
/// Undocumented
4139+
/// </summary>
41334140
public bool? HideEmptyShared { get; set; }
41344141

4142+
/// <summary>
4143+
/// Internal flag to indicate if there is a custom tooltip setup
4144+
/// </summary>
4145+
public bool CustomTooltip { get; internal set; }
4146+
41354147
/// <inheritdoc cref="ApexCharts.CustomFunction"/>
41364148
/// <summary>
41374149
/// Draw a custom html tooltip instead of the default one based on the values provided in the function arguments.

src/Blazor-ApexCharts/wwwroot/js/blazor-apexcharts.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ window.blazor_apexchart = {
212212
options.dotNetObject = dotNetObject;
213213
options.chart.events = {};
214214

215+
if (options.tooltip != undefined && options.tooltip.customTooltip == true) {
216+
options.tooltip.custom = function ({ series, seriesIndex, dataPointIndex, w }) {
217+
var sourceId = 'apex-tooltip-' + w.globals.chartID;
218+
var source = document.getElementById(sourceId);
219+
if (source) {
220+
return source.innerHTML;
221+
}
222+
return '...'
223+
};
224+
}
225+
215226
if (events.hasDataPointLeave === true) {
216227
options.chart.events.dataPointMouseLeave = function (event, chartContext, config) {
217228
var selection = {

0 commit comments

Comments
 (0)