-
Notifications
You must be signed in to change notification settings - Fork 164
Added Line Chart Interpolation sample #174
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| @page "/charts/line/interpolation" | ||
| @using ChartJs.Blazor.LineChart | ||
| @layout SampleLayout | ||
|
|
||
| <Chart Config="_config" @ref="_chart"></Chart> | ||
|
|
||
| <button @onclick="RandomizeData">Randomize Data</button> | ||
|
|
||
| @code { | ||
| private const int InitalCount = 7; | ||
| private int?[] datapoints; | ||
| Random rand = new Random(); | ||
andreassundstrom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private LineConfig _config; | ||
| private Chart _chart; | ||
|
|
||
| protected override void OnInitialized() | ||
| { | ||
| datapoints = new int?[] { 0, 20, 20, 60, 60, 120, null, 180, 120, 125, 105, 110, 170 }; | ||
|
|
||
| IEnumerable<string> labels = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; | ||
andreassundstrom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| _config = new LineConfig | ||
| { | ||
| Options = new LineOptions | ||
| { | ||
| Responsive = true, | ||
| Title = new OptionsTitle | ||
| { | ||
| Display = true, | ||
| Text = "ChartJs.Blazor Line Chart - Cubic interpolation mode" | ||
| }, | ||
| Tooltips = new Tooltips | ||
| { | ||
| Mode = InteractionMode.Nearest, | ||
| Intersect = true | ||
| }, | ||
| Hover = new Hover | ||
| { | ||
| Mode = InteractionMode.Nearest, | ||
| Intersect = true | ||
| }, | ||
| Scales = new Scales | ||
| { | ||
|
|
||
| XAxes = new List<CartesianAxis> | ||
| { | ||
andreassundstrom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| new CategoryAxis | ||
| { | ||
| ScaleLabel = new ScaleLabel | ||
| { | ||
| LabelString = "Month" | ||
| } | ||
| } | ||
| }, | ||
| YAxes = new List<CartesianAxis> | ||
| { | ||
| new LinearCartesianAxis | ||
| { | ||
| ScaleLabel = new ScaleLabel | ||
| { | ||
| LabelString = "Value", | ||
| Display = true | ||
| }, | ||
| Ticks = new LinearCartesianTicks | ||
| { | ||
| SuggestedMin = -10, | ||
| SuggestedMax = 200 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| IDataset<int?> dataset1 = new LineDataset<int?>(datapoints) | ||
| { | ||
| Label = "Cubic interpolation (monotone)", | ||
| BackgroundColor = ColorUtil.FromDrawingColor(ChartColors.Red), | ||
| BorderColor = ColorUtil.FromDrawingColor(ChartColors.Red), | ||
| Fill = FillingMode.Disabled, | ||
| CubicInterpolationMode = CubicInterpolationMode.Monotone, | ||
| LineTension = 0.4 | ||
| }; | ||
| IDataset<int?> dataset2 = new LineDataset<int?>(datapoints) | ||
| { | ||
| Label = "Cubic interpolation", | ||
| BackgroundColor = ColorUtil.FromDrawingColor(ChartColors.Blue), | ||
| BorderColor = ColorUtil.FromDrawingColor(ChartColors.Blue), | ||
| Fill = FillingMode.Disabled, | ||
| LineTension = 0.4 | ||
| }; | ||
|
|
||
| IDataset<int?> dataset3 = new LineDataset<int?>(datapoints) | ||
| { | ||
| Label = "Linear interpolation (default)", | ||
| BackgroundColor = ColorUtil.FromDrawingColor(ChartColors.Green), | ||
| BorderColor = ColorUtil.FromDrawingColor(ChartColors.Green), | ||
| Fill = FillingMode.Disabled, | ||
| LineTension = 0 | ||
|
|
||
| }; | ||
|
|
||
| _config.Data.Labels.AddRange(labels); | ||
| _config.Data.Datasets.Add(dataset1); | ||
| _config.Data.Datasets.Add(dataset2); | ||
| _config.Data.Datasets.Add(dataset3); | ||
| } | ||
|
|
||
| private void RandomizeData() | ||
| { | ||
|
|
||
andreassundstrom marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for(int i = 0; i < datapoints.Count(); i++) | ||
| { | ||
| datapoints[i] = rand.NextDouble() < 0.05 ? null : (int?)RandomScalingFactor(); | ||
| } | ||
|
|
||
| foreach (IDataset<int?> dataset in _config.Data.Datasets) | ||
| { | ||
| dataset.Clear(); | ||
| dataset.AddRange(datapoints); | ||
| } | ||
|
|
||
| _chart.Update(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,10 +23,14 @@ | |
| "Title": "Basic", | ||
| "Path": "charts/line/basic" | ||
| }, | ||
| { | ||
| "Title": "Stepped", | ||
| "Path": "charts/line/stepped" | ||
| } | ||
| { | ||
| "Title": "Stepped", | ||
| "Path": "charts/line/stepped" | ||
| }, | ||
| { | ||
| "Title": "Interpolation", | ||
| "Path": "charts/line/interpolation" | ||
| } | ||
|
||
| ] | ||
| }, | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.