-
Notifications
You must be signed in to change notification settings - Fork 81
Added new kb article chart-display-empty #2699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Tsvetomir-Hr
merged 5 commits into
master
from
new-kb-chart-display-empty-69ccb76854994efc96c3d6acabc8e054
Jan 20, 2025
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b7d933b
Added new kb article chart-display-empty
00c90e4
chore: kb polish
Tsvetomir-Hr bdf6567
chore: update kb title and add link in docs
Tsvetomir-Hr 95615f6
apply suggested changes and polish example
Tsvetomir-Hr c21def8
chore: polish kb article
Tsvetomir-Hr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| --- | ||
| title: How to Show Empty Chart Instead the Default No Data Template | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| description: Learn how to show an empty Chart component when there is no data, instead of displaying the default No Data template. | ||
| type: how-to | ||
| page_title: How to Show Empty Chart Instead the Default No Data Template | ||
| slug: chart-kb-display-empty-chart | ||
| tags: charts, blazor, no data template, empty chart | ||
| res_type: kb | ||
| ticketid: 1675313 | ||
| --- | ||
|
|
||
| ## Environment | ||
| <table> | ||
| <tbody> | ||
| <tr> | ||
| <td>Product</td> | ||
| <td>Chart for Blazor</td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
|
|
||
| ## Description | ||
|
|
||
| As of version 7.1.0, the [No Data Template](slug://chart-no-data-template) was introduced for Charts in Blazor. In some scenarios, displaying an empty Chart, rather than the No Data template, is preferred when there is no data. This knowledge base article also answers the following questions: | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - How can I hide the No Data Template in Blazor Charts? | ||
| - Is it possible to display an empty Chart in Blazor when there's no data? | ||
| - Can I override the No Data Template in Blazor Charts? | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Solution | ||
|
|
||
| To display an empty Chart when there is no data, [override the default theme styles](slug://themes-override) by applying custom CSS. The following example demonstrates how to achieve an empty Chart display by hiding the No Data Template overlay through CSS. | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
|
|
||
| ````RAZOR | ||
| <TelerikButton OnClick="@UpdateData">@ButtonContent</TelerikButton> | ||
| <br /> | ||
| <TelerikChart @ref="ChartRef" Width="800px" Height="400px"> | ||
| <ChartTitle Text="Product Sales Over the Years" Position="@ChartTitlePosition.Bottom"></ChartTitle> | ||
| <ChartSeriesItems> | ||
| <ChartSeries Type="ChartSeriesType.Column" | ||
| Data="@ChartData" | ||
| Name="Product Sales" | ||
| Field="@nameof(ChartSeriesData.ProductSales)" | ||
| CategoryField="@nameof(ChartSeriesData.Year)"> | ||
| </ChartSeries> | ||
| </ChartSeriesItems> | ||
| </TelerikChart> | ||
| <style> | ||
| .k-chart-overlay { | ||
| display: none; | ||
| } | ||
| </style> | ||
| @code { | ||
| private const string Add = "Add Data"; | ||
| private const string Remove = "Remove Data"; | ||
| private TelerikChart ChartRef { get; set; } | ||
| private List<ChartSeriesData> ChartData { get; set; } = new List<ChartSeriesData>(); | ||
| private string ButtonContent { get; set; } = Add; | ||
| private void UpdateData() | ||
| { | ||
| if (ChartData == null || ChartData?.Count() == 0) | ||
| { | ||
| ChartData = ChartSeriesData.GenerateData(); | ||
| ButtonContent = Remove; | ||
| } | ||
| else | ||
| { | ||
| // Clear the data | ||
| ChartData = new List<ChartSeriesData>(); | ||
| ButtonContent = Add; | ||
| } | ||
| ChartRef.Refresh(); // Refresh the Chart | ||
| } | ||
| public class ChartSeriesData | ||
| { | ||
| public int ProductSales { get; set; } | ||
| public int Year { get; set; } | ||
| public static List<ChartSeriesData> GenerateData() | ||
| { | ||
| List<ChartSeriesData> data = new List<ChartSeriesData> | ||
| { | ||
| new ChartSeriesData { ProductSales = 120, Year = 2020 }, | ||
| new ChartSeriesData { ProductSales = 180, Year = 2021 }, | ||
| new ChartSeriesData { ProductSales = 150, Year = 2022 }, | ||
| new ChartSeriesData { ProductSales = 210, Year = 2023 }, | ||
| new ChartSeriesData { ProductSales = 90, Year = 2024 } | ||
| }; | ||
| return data; | ||
| } | ||
| } | ||
| } | ||
| ```` | ||
|
|
||
| By applying the `.k-chart-overlay { display: none; }` style, the No Data template overlay is hidden, allowing the Chart to appear empty when there is no data. | ||
Tsvetomir-Hr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## See Also | ||
|
|
||
| - [Blazor Charts Overview](slug://components/chart/overview) | ||
| - [Override Theme Styles](slug://themes-override) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.