Live data
Since 0.1.0-alpha.22Requests per second
To read a chart's data again on an interval, set Refresh and give the chart an id. Here the last two minutes of requests come in every 5 seconds.
Static
Preview
| Time | Requests |
|---|---|
| 2:33:36 | 1,033 |
| 2:33:37 | 1,016 |
| 2:33:38 | 998 |
| 2:33:39 | 1,021 |
| 2:33:40 | 1,001 |
| 2:33:41 | 982 |
| 2:33:42 | 963 |
| 2:33:43 | 945 |
| 2:33:44 | 929 |
| 2:33:45 | 915 |
| 2:33:46 | 903 |
| 2:33:47 | 894 |
| 2:33:48 | 887 |
| 2:33:49 | 924 |
| 2:33:50 | 922 |
| 2:33:51 | 922 |
| 2:33:52 | 924 |
| 2:33:53 | 927 |
| 2:33:54 | 931 |
| 2:33:55 | 936 |
| 2:33:56 | 940 |
| 2:33:57 | 944 |
| 2:33:58 | 947 |
| 2:33:59 | 947 |
| 2:34:00 | 987 |
| 2:34:01 | 983 |
| 2:34:02 | 977 |
| 2:34:03 | 967 |
| 2:34:04 | 955 |
| 2:34:05 | 940 |
| 2:34:06 | 922 |
| 2:34:07 | 902 |
| 2:34:08 | 880 |
| 2:34:09 | 857 |
| 2:34:10 | 873 |
| 2:34:11 | 849 |
| 2:34:12 | 824 |
| 2:34:13 | 800 |
| 2:34:14 | 777 |
| 2:34:15 | 756 |
| 2:34:16 | 737 |
| 2:34:17 | 720 |
| 2:34:18 | 707 |
| 2:34:19 | 696 |
| 2:34:20 | 729 |
| 2:34:21 | 723 |
| 2:34:22 | 721 |
| 2:34:23 | 721 |
| 2:34:24 | 722 |
| 2:34:25 | 725 |
| 2:34:26 | 729 |
| 2:34:27 | 734 |
| 2:34:28 | 739 |
| 2:34:29 | 742 |
| 2:34:30 | 786 |
| 2:34:31 | 787 |
| 2:34:32 | 786 |
| 2:34:33 | 783 |
| 2:34:34 | 778 |
| 2:34:35 | 770 |
| 2:34:36 | 759 |
| 2:34:37 | 746 |
| 2:34:38 | 731 |
| 2:34:39 | 714 |
| 2:34:40 | 696 |
| 2:34:41 | 718 |
| 2:34:42 | 699 |
| 2:34:43 | 679 |
| 2:34:44 | 661 |
| 2:34:45 | 644 |
| 2:34:46 | 628 |
| 2:34:47 | 615 |
| 2:34:48 | 604 |
| 2:34:49 | 597 |
| 2:34:50 | 592 |
| 2:34:51 | 631 |
| 2:34:52 | 633 |
| 2:34:53 | 637 |
| 2:34:54 | 644 |
| 2:34:55 | 653 |
| 2:34:56 | 664 |
| 2:34:57 | 676 |
| 2:34:58 | 689 |
| 2:34:59 | 703 |
| 2:35:00 | 715 |
| 2:35:01 | 768 |
| 2:35:02 | 779 |
| 2:35:03 | 788 |
| 2:35:04 | 795 |
| 2:35:05 | 799 |
| 2:35:06 | 801 |
| 2:35:07 | 800 |
| 2:35:08 | 796 |
| 2:35:09 | 791 |
| 2:35:10 | 783 |
| 2:35:11 | 814 |
| 2:35:12 | 804 |
| 2:35:13 | 792 |
| 2:35:14 | 781 |
| 2:35:15 | 769 |
| 2:35:16 | 759 |
| 2:35:17 | 750 |
| 2:35:18 | 743 |
| 2:35:19 | 738 |
| 2:35:20 | 735 |
| 2:35:21 | 736 |
| 2:35:22 | 780 |
| 2:35:23 | 786 |
| 2:35:24 | 794 |
| 2:35:25 | 805 |
| 2:35:26 | 818 |
| 2:35:27 | 833 |
| 2:35:28 | 849 |
| 2:35:29 | 865 |
| 2:35:30 | 882 |
| 2:35:31 | 898 |
| 2:35:32 | 954 |
| 2:35:33 | 968 |
| 2:35:34 | 980 |
| 2:35:35 | 989 |
Code
@* An API's requests per second over the last two minutes, read again every 5 seconds: on a static
page the chart's frame is fetched again, on an interactive one OnRefresh reloads the samples. *@
<Chart id="api-requests" Items="_samples" Argument="s => s.Time" Title="Requests per second, last 2 minutes (UTC)"
Refresh="TimeSpan.FromSeconds(5)" RefreshFrom="/frame/chart-live-refresh" OnRefresh="Load">
<ChartValueAxis Min="0" Format="N0" />
<ChartArgumentAxis Zoom Format="h:mm:ss" />
<ChartAreaSeries Value="s => s.Requests" Name="Requests" />
</Chart>
{
private record Sample(DateTime Time, int Requests);
private Sample[] _samples = Read();
private void Load() => _samples = Read();
// A sample a second, ending now. A real app reads its metrics store; here each second's value
// comes from the time itself, so every request sees the same history.
private static Sample[] Read()
{
var now = DateTime.UtcNow;
var end = now.AddTicks(-(now.Ticks % TimeSpan.TicksPerSecond));
return Enumerable.Range(0, 120).Select(i =>
{
var time = end.AddSeconds(i - 119);
var s = time.Ticks / TimeSpan.TicksPerSecond;
return new Sample(time, (int)(820 + 160 * Math.Sin(s / 23.0) + 70 * Math.Sin(s / 5.0) + s * 37 % 41));
}).ToArray();
}
}On a static page the page is fetched again and the chart drawn from it, found by its id. RefreshFrom names a lighter page that renders the same chart, here the example's own frame. A failed fetch keeps the last drawing.
Nothing is fetched while the tab is hidden or the chart is off-screen. On a static page an update also waits while your pointer or focus is in the chart, so nothing moves while you read it.
On an interactive page Refresh raises OnRefresh instead, for you to load new Items. When your app pushes data on its own, from a timer or SignalR, set Live and change Items.
Pause updates keeps the chart still, as WCAG asks of content that updates on its own. Paused starts it paused, and @bind-Paused with HidePause pauses it from your own control.
The item you point at or reach with the keys stays the same item as new data arrives. Zoomed in at the latest item, the view moves on with new data; zoomed into the past, it stays there. Screen readers hear nothing on each update.
The other charts, Sparkline and Gauge take Refresh, RefreshFrom and OnRefresh too, with no Pause button or kept item: on a dashboard, give them the same interval as its charts.