-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
232a8d0
commit 7a2ea2a
Showing
12 changed files
with
316 additions
and
69 deletions.
There are no files selected for viewing
This file contains 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,81 @@ | ||
@page "/backup" | ||
@using BlazorComponents.Shared | ||
|
||
<div class="container"> | ||
<h2>Chart JS charts using Blazor</h2> | ||
<div class="row"> | ||
<button class="btn btn-primary" onclick="@UpdateChart">Update Chart </button> | ||
</div> | ||
<ChartJsBarChart ref="barChartJs" Chart="@blazorBarChartJS" Width="600" Height="300" /> | ||
</div> | ||
|
||
|
||
@functions { | ||
|
||
public ChartJSBarChart blazorBarChartJS { get; set; } = new ChartJSBarChart(); | ||
ChartJsBarChart barChartJs; | ||
|
||
protected override void OnInit() | ||
{ | ||
blazorBarChartJS = new ChartJSBarChart() | ||
{ | ||
ChartType = "bar", | ||
CanvasId = "myFirstBarChart", | ||
Options = new ChartJsOptions() | ||
{ | ||
Text = "Sample chart from Blazor", | ||
BorderWidth = 1, | ||
Display = true | ||
}, | ||
Data = new ChartJsBarData() | ||
{ | ||
Labels = new List<string>() { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }, | ||
Datasets = new List<ChartJsBarDataset>() | ||
{ | ||
new ChartJsBarDataset() | ||
{ | ||
Label = "# of Votes from blazor", | ||
BackgroundColor = "#cc65fe", | ||
BorderColor = "#cc65fe", | ||
PointHoverRadius = 2, | ||
Data = new List<double>(){ 19.187,12.2253,5.5,3,3,2} | ||
}, | ||
new ChartJsBarDataset() | ||
{ | ||
Label = "# of Likes from blazor", | ||
BackgroundColor = "#36a2eb", | ||
BorderColor = "#36a2eb", | ||
PointHoverRadius = 2, | ||
Data = new List<int>(){ 30,10,15,13,13,12}.Select<int,double>(i=> i).ToList() | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
public async Task<bool> UpdateChart() | ||
{ | ||
//Update existing dataset | ||
blazorBarChartJS.Data.Labels.Add($"New{DateTime.Now.Second}"); | ||
var firstDataSet = blazorBarChartJS.Data.Datasets[0]; | ||
firstDataSet.Data.Add(DateTime.Now.Second); | ||
StateHasChanged(); | ||
//Add new dataset | ||
//blazorLineChartJS.Data.Datasets.Add(new ChartJsLineDataset() | ||
//{ | ||
// BackgroundColor = "#cc65fe", | ||
// BorderColor = "#cc65fe", | ||
// Label = "# of Votes from blazor 1", | ||
// Data = new List<int> {20,21,12,3,4,4}, | ||
// Fill = true, | ||
// BorderWidth = 2, | ||
// PointRadius = 3, | ||
// PointBorderWidth = 1 | ||
//}); | ||
//var done = await barChartJs.UpdateChart(blazorBarChartJS); | ||
//StateHasChanged(); | ||
return true; | ||
} | ||
} |
This file contains 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 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 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,112 @@ | ||
@page "/multiple" | ||
@using BlazorComponents.Shared | ||
|
||
<div class="container"> | ||
<h2>Chart JS Bar Chart Using Blazor</h2> | ||
<div class="row"> | ||
<button class="btn btn-primary" onclick="@UpdateBarChart">Update Chart </button> | ||
</div> | ||
<ChartJsBarChart ref="barChartJs" Chart="@blazorBarChartJS" Width="600" Height="300" /> | ||
|
||
<h2>Chart JS Line Chart Using Blazor</h2> | ||
<div class="row"> | ||
<button class="btn btn-primary" onclick="@UpdateLineChart">Update Chart </button> | ||
</div> | ||
<ChartJsLineChart ref="lineChartJs" Chart="@blazorLineChartJS" Width="600" Height="300" /> | ||
</div> | ||
|
||
|
||
@functions { | ||
|
||
public ChartJSBarChart blazorBarChartJS { get; set; } = new ChartJSBarChart(); | ||
ChartJsBarChart barChartJs; | ||
public ChartJSLineChart blazorLineChartJS { get; set; } = new ChartJSLineChart(); | ||
ChartJsLineChart lineChartJs; | ||
|
||
protected override void OnInit() | ||
{ | ||
|
||
blazorBarChartJS = new ChartJSBarChart() | ||
{ | ||
ChartType = "bar", | ||
CanvasId = "myFirstBarChart", | ||
Options = new ChartJsOptions() | ||
{ | ||
Text = "Sample chart from Blazor", | ||
BorderWidth = 1, | ||
Display = true | ||
}, | ||
Data = new ChartJsBarData() | ||
{ | ||
Labels = new List<string>() { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }, | ||
Datasets = new List<ChartJsBarDataset>() | ||
{ | ||
new ChartJsBarDataset() | ||
{ | ||
Label = "# of Votes from blazor", | ||
BackgroundColor = "#cc65fe", | ||
BorderColor = "#cc65fe", | ||
PointHoverRadius = 2, | ||
Data = new List<double>(){ 19.187,12.2253,5.5,3,3,2} | ||
}, | ||
new ChartJsBarDataset() | ||
{ | ||
Label = "# of Likes from blazor", | ||
BackgroundColor = "#36a2eb", | ||
BorderColor = "#36a2eb", | ||
PointHoverRadius = 2, | ||
Data = new List<int>(){ 30,10,15,13,13,12}.Select<int,double>(i=> i).ToList() | ||
} | ||
} | ||
} | ||
}; | ||
|
||
blazorLineChartJS = new ChartJSLineChart() | ||
{ | ||
ChartType = "line", | ||
CanvasId = "myFirstLineChart", | ||
Options = new ChartJsOptions() | ||
{ | ||
Text = "Sample chart from Blazor", | ||
Display = true, | ||
Responsive = false | ||
}, | ||
Data = new ChartJsLineData() | ||
{ | ||
Labels = new List<string>() { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }, | ||
Datasets = new List<ChartJsLineDataset>() | ||
{ | ||
new ChartJsLineDataset() | ||
{ | ||
BackgroundColor = "#ff6384", | ||
BorderColor = "#ff6384", | ||
Label = "# of Votes from blazor", | ||
Data = new List<int>{ 19,12,5,3,3,2}.Select<int,double>(i=> i).ToList(), | ||
Fill = false, | ||
BorderWidth = 2, | ||
PointRadius = 3, | ||
PointBorderWidth=1 | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
public async Task<bool> UpdateBarChart() | ||
{ | ||
//Update existing dataset | ||
blazorBarChartJS.Data.Labels.Add($"New{DateTime.Now.Second}"); | ||
var firstDataSet = blazorBarChartJS.Data.Datasets[0]; | ||
firstDataSet.Data.Add(DateTime.Now.Second); | ||
|
||
return true; | ||
} | ||
|
||
public void UpdateLineChart() | ||
{ | ||
//Update existing dataset | ||
blazorLineChartJS.Data.Labels.Add($"New{DateTime.Now.Second}"); | ||
var firstDataSet = blazorLineChartJS.Data.Datasets[0]; | ||
firstDataSet.Data.Add(DateTime.Now.Second); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.