Skip to content

Commit 21edf79

Browse files
committed
LineChart: Interpolation modes demo added.
1 parent 391f176 commit 21edf79

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

BlazorExpress.ChartJS.Demo.RCL/Pages/Demos/LineChart/LineChartDocumentation.razor

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@
8383
<Demo Type="typeof(LineChart_Demo_04_Locale)" Tabs="true" />
8484
</Section>
8585

86+
<Section Class="p-0" Size="HeadingSize.H4" Name="Interpolation modes" PageUrl="@pageUrl" Link="interpolation-modes">
87+
<Block>
88+
TODO: Add a description for the Interpolation Modes section.
89+
</Block>
90+
<Demo Type="typeof(LineChart_Demo_05_Interpolation_Modes)" Tabs="true" />
91+
</Section>
92+
8693
@code {
8794
private const string pageUrl = DemoRouteConstants.Demos_LineChart;
8895
private const string pageTitle = "Line Chart";
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<LineChart @ref="lineChart" Width="600" />
2+
3+
@code {
4+
private LineChart lineChart = default!;
5+
private LineChartOptions lineChartOptions = default!;
6+
private ChartData chartData = default!;
7+
8+
private int dataCount = 12;
9+
private List<double?> datapoints = [0, 20, 20, 60, 60, 120, null, 180, 120, 125, 105, 110, 170];
10+
private int datasetsCount;
11+
private Random random = new();
12+
13+
protected override void OnInitialized()
14+
{
15+
chartData = new ChartData { Labels = GetDefaultDataLabels(), Datasets = GetDefaultDataSets() };
16+
lineChartOptions = new()
17+
{
18+
IndexAxis = "x",
19+
Interaction = new Interaction { Mode = InteractionMode.Index, Intersect = false },
20+
Responsive = true,
21+
};
22+
}
23+
24+
protected override async Task OnAfterRenderAsync(bool firstRender)
25+
{
26+
if (firstRender)
27+
{
28+
await lineChart.InitializeAsync(chartData, lineChartOptions);
29+
}
30+
await base.OnAfterRenderAsync(firstRender);
31+
}
32+
33+
#region Data Preparation
34+
35+
private List<string> GetDefaultDataLabels()
36+
{
37+
var labels = new List<string>();
38+
39+
for (var index = 0; index < dataCount; index++)
40+
labels.Add(index.ToString());
41+
42+
return labels;
43+
}
44+
45+
private List<IChartDataset> GetDefaultDataSets()
46+
{
47+
var datasets = new List<IChartDataset>();
48+
49+
// 1.
50+
datasets.Add(new LineChartDataset
51+
{
52+
Label = "Cubic interpolation (monotone)",
53+
Data = datapoints,
54+
BorderColor = ColorUtility.CategoricalSixColors[0].ToColor().ToRgbString(),
55+
CubicInterpolationMode = "monotone",
56+
Fill = false,
57+
Tension = 0.4,
58+
});
59+
60+
// 2.
61+
datasets.Add(new LineChartDataset
62+
{
63+
Label = "Cubic interpolation",
64+
Data = datapoints,
65+
BorderColor = ColorUtility.CategoricalSixColors[1].ToColor().ToRgbString(),
66+
Fill = false,
67+
Tension = 0.4,
68+
});
69+
70+
// 3.
71+
datasets.Add(new LineChartDataset
72+
{
73+
Label = "Linear interpolation (default)",
74+
Data = datapoints,
75+
BorderColor = ColorUtility.CategoricalSixColors[2].ToColor().ToRgbString(),
76+
Fill = false,
77+
});
78+
79+
return datasets;
80+
}
81+
82+
#endregion Data Preparation
83+
}

0 commit comments

Comments
 (0)