The ApexChartOptions<T> class provides an accessible "Title" property that can be set, suggesting that a plot's title may be set through the options class and not just the "Title" parameter on an ApexChart component. However, if a user tries to do this and does not also set the Title parameter, the option gets set to null and the plot has no title.
Steps to Reproduce
Create an instance of ApexChartOptions<TItem> named Options
Set Options.Title = new Title { Text = "My Title Name" };
Create an ApexChart instance and set the options parameter equal to the Options class just created
if (string.IsNullOrEmpty(Title))
{
Options.Title = null;
}
else
{
if (Options.Title == null) { Options.Title = new Title(); }
Options.Title.Text = Title;
}
In this, if the Title parameter is null the Options.Title will automatically be set to null, regardless of it's current value. To make it more optional, and allow for the title to be set through the Options class, I suggest changing the logic to something similar to
if(Title is not null)
{
if(Options.Title == null) { Options.Title = new Title(); }
Options.Title.Text = Title;
}
This way, if the title parameter is set, it will take priority over what the Options class may have already provided, but if it is null, the current options are respected, or the Options remain null.
Summary
The
ApexChartOptions<T>
class provides an accessible "Title" property that can be set, suggesting that a plot's title may be set through the options class and not just the "Title" parameter on anApexChart
component. However, if a user tries to do this and does not also set the Title parameter, the option gets set to null and the plot has no title.Steps to Reproduce
ApexChartOptions<TItem>
named OptionsOptions.Title = new Title { Text = "My Title Name" };
ApexChart
instance and set the options parameter equal to the Options class just createdSuggested Solution
This seems to stem from ApexChart.razor.cs OnParametersSet which has these lines:
In this, if the Title parameter is null the Options.Title will automatically be set to null, regardless of it's current value. To make it more optional, and allow for the title to be set through the Options class, I suggest changing the logic to something similar to
This way, if the title parameter is set, it will take priority over what the Options class may have already provided, but if it is null, the current options are respected, or the Options remain null.