Hi Support Team,
in our project we are using Telerik Chart and has required to update theme of chart from dark to light and light to dark.
telerik chart in child razor page and dark/light button in mainlayout.razor file but telerik chart updating theme when click on button exist telerik chart razor page. as below link it is an existing issue.
please advice how to resolve the issue.
Hi Haribabu,
Thank you for sharing your code, which has been immensely helpful in gaining a comprehensive understanding of the scenario and pinpointing the root cause of the issue. Allow me to share my observations and propose a solution.
The challenge at hand stems from the Chart within the child component not automatically receiving notifications for theme changes. Manual intervention is required to ensure the Chart is refreshed accordingly. To address this and attain the desired outcome, the most straightforward approach is to introduce a service responsible for notifying the Chart of any theme changes and triggering the necessary refresh.
For your convenience, I've prepared a runnable project enclosed in the attached "chart-theme-change.zip". Please take the time to explore and test it to witness the desired result.
Should you encounter any challenges with the provided sample, rest assured that I stand ready to extend my assistance.
Regards,
Hristian Stefanov
Progress Telerik
Hi Hristian Stefanov,
i am using following code to using in my project
Child Component which is rendering telerik chart
<TelerikChart @ref="@ChartRef" Transitions="false">
<ChartSeriesItems>
@*configuring the chart data , color and field *@
<ChartSeries Type="ChartSeriesType.Pie"
Data="@pieData"
ColorField="@nameof(MyPieChartModel.SegmentColor)"
Field="@nameof(MyPieChartModel.SegmentValue)"
CategoryField="@nameof(MyPieChartModel.SegmentName)">
<ChartSeriesLabels Visible="true"
Template="#=category#"
Background="transparent"
Position="ChartSeriesLabelsPosition.OutsideEnd" />
</ChartSeries>
</ChartSeriesItems>
<ChartTitle Text="WorkSpaces"></ChartTitle>
<ChartLegend Visible="false"></ChartLegend>
</TelerikChart>
public class MyPieChartModel
{
public string SegmentName { get; set; }
public double SegmentValue { get; set; }
public string SegmentColor { get; set; }
}
public List<MyPieChartModel> pieData = new List<MyPieChartModel>();
private async Task RebindComponents()
{
Log.Debug("Enter into method RebindComponents");
try
{
DmsWorkspaceDto dmsWorkspaceDto = new DmsWorkspaceDto()
{
};
WorkspaceCountAll = //Calling API
WorkspacePublicCount = //Calling API
WorkspacePrivateCount =//Calling API
pieData = new List<MyPieChartModel>()
{
new MyPieChartModel
{
SegmentName = "Workspaces All ("+WorkspaceCountAll+")",
SegmentValue = WorkspaceCountAll,
SegmentColor=Countallcolor
},
new MyPieChartModel
{
SegmentName = "Workspaces Public/View ("+WorkspacePublicCount+")",
SegmentValue = WorkspacePublicCount,
SegmentColor=Publiccolor
},
new MyPieChartModel
{
SegmentName = "Workspaces Private ("+WorkspacePrivateCount+")",
SegmentValue = WorkspacePrivateCount,
SegmentColor=Privatecolor
}
};
ChartRef.Refresh();
StateHasChanged();
}
catch (Exception ex)
{
Log.Error("Problem encountered at:RebindComponents: {message}", ex.Message);
}
Log.Debug("Exit from method RebindComponents");
}
MainLayout.Razor
on button clicks calling following methods to switch pages from light to dark and dark to lightHi Haribabu,
I've made an attempt to recreate the issue you described by creating an example project that follows our knowledge base article for the ability to change the theme dynamically. However, on my end, it seems that the changed theme applies to every component correctly. It's possible that I may be overlooking a configuration detail that you are testing, which could help me reproduce the problem.
To gain a more comprehensive understanding of the scenario and offer a tailored solution, please share a runnable sample that demonstrates the issue. This will enable me to thoroughly investigate the case.
I eagerly await your response and the opportunity to assist further.
Regards,
Hristian Stefanov
Progress Telerik