Skip to content

Commit

Permalink
Charts update + demos update (#307)
Browse files Browse the repository at this point in the history
* Charts update + demos update
  • Loading branch information
gvreddy04 authored Jul 30, 2023
1 parent 24a0378 commit bbf7d53
Show file tree
Hide file tree
Showing 84 changed files with 3,119 additions and 1,093 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@page "/charts/bar-chart"

<PageTitle>@title</PageTitle>

<MetaTags PageUrl="@pageUrl" Title="@title" Description="@description" ImageUrl="@imageUrl" />

<h1>Blazor Bar Chart</h1>
<div class="lead mb-3">
A Blazor Bootstrap bar chart component is used to represent data values as vertical bars. It is sometimes used to show trend data and to compare multiple data sets side by side.
</div>

<SectionHeading Size="HeadingSize.H4" Text="How it works" PageUrl="@pageUrl" HashTagName="how-it-works" />
<div class="mb-3">
In the following example, a categorical 12-color palette is used.
</div>
<Callout Heading="TIP" Type="CalloutType.Tip">
For data visualization, you can use the predefined palettes <code>ColorBuilder.CategoricalTwelveColors</code> for a 12-color palette and <code>ColorBuilder.CategoricalSixColors</code> for a 6-color palette.
These palettes offer a range of distinct and visually appealing colors that can be applied to represent different categories or data elements in your visualizations.
</Callout>
<Demo Type="typeof(BarChart_Demo_01_Examples)" Tabs="true" />

<SectionHeading Size="HeadingSize.H4" Text="Horizontal bar chart" PageUrl="@pageUrl" HashTagName="horizontal-bar-chart" />
<Demo Type="typeof(BarChart_Demo_02_Horizontal_BarChart)" Tabs="true" />

<SectionHeading Size="HeadingSize.H4" Text="Stacked bar chart" PageUrl="@pageUrl" HashTagName="stacked-bar-chart" />
<Demo Type="typeof(BarChart_Demo_03_Stacked_BarChart)" Tabs="true" />

<SectionHeading Size="HeadingSize.H4" Text="Locale" PageUrl="@pageUrl" HashTagName="locale" />
<div class="my-3">
By default, the chart is using the default locale of the platform on which it is running.
In the following example, you will see the chart in the <b>German</b> locale (<b>de_DE</b>).
</div>
<Demo Type="typeof(BarChart_Demo_04_Locale)" Tabs="true" />

@code {
private string pageUrl = "/charts/bar-chart";
private string title = "Blazor Bar Chart";
private string description = "A Blazor Bootstrap bar chart component is used to represent data values as vertical bars. It is sometimes used to show trend data and to compare multiple data sets side by side.";
private string imageUrl = "https://i.imgur.com/FGgEMp6.jpg";
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
@using BlazorBootstrap.Extensions
@using BlazorBootstrap.Utilities;

<BarChart @ref="barChart" Width="800" Class="mb-4" />
<BarChart @ref="barChart" Width="800" Class="mb-4" />

<Button Type="ButtonType.Button" Color="ButtonColor.Primary" Size="Size.Small" @onclick="async () => await RandomizeAsync()"> Randomize </Button>
<Button Type="ButtonType.Button" Color="ButtonColor.Primary" Size="Size.Small" @onclick="async () => await AddDatasetAsync()"> Add Dataset </Button>
Expand Down Expand Up @@ -83,11 +80,11 @@
if (labelsCount >= 12)
return;

var data = new List<ChartDatasetData>();
var data = new List<IChartDatasetData>();
foreach (var dataset in chartData.Datasets)
{
if (dataset is BarChartDataset barChartDataset)
data.Add(new ChartDatasetData(barChartDataset.Label, random.Next(200)));
data.Add(new BarChartDatasetData(barChartDataset.Label, random.Next(200)));
}

chartData = await barChart.AddDataAsync(chartData, GetNextDataLabel(), data);
Expand Down Expand Up @@ -121,13 +118,10 @@

private BarChartDataset GetRandomBarChartDataset()
{
// random color
var c = ColorBuilder.CategoricalTwelveColors[datasetsCount].ToColor();

datasetsCount += 1;

Console.WriteLine($"Bar Chart: Color Name: {c.Name}, HEX: {c.ToHexString()}, RGB: {c.ToRgbString()}, IsNamedColor: {c.IsNamedColor}");

return new BarChartDataset()
{
Label = $"Product {datasetsCount}",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<BarChart @ref="barChart" Height="300" Class="mb-4" />

@code {
private BarChart barChart = default!;
private BarChartOptions barChartOptions = default!;
private ChartData chartData = default!;

protected override void OnInitialized()
{
var labels = new List<string> { "Chrome", "Firefox", "Safari", "Edge" };
var datasets = new List<IChartDataset>();

var dataset1 = new BarChartDataset()
{
Data = new List<double> { 55000, 15000, 18000, 21000 },
BackgroundColor = new List<string> { ColorBuilder.CategoricalTwelveColors[0] },
BorderColor = new List<string> { ColorBuilder.CategoricalTwelveColors[0] },
BorderWidth = new List<double> { 0 },
};
datasets.Add(dataset1);

chartData = new ChartData {
Labels = labels,
Datasets = datasets };

barChartOptions = new BarChartOptions();
barChartOptions.Responsive = true;
barChartOptions.Interaction = new Interaction { Mode = InteractionMode.Y };
barChartOptions.IndexAxis = "y";

barChartOptions.Scales.X.Title.Text = "Visitors";
barChartOptions.Scales.X.Title.Display = true;

barChartOptions.Scales.Y.Title.Text = "Browser";
barChartOptions.Scales.Y.Title.Display = true;

barChartOptions.Plugins.Legend.Display = false;
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await barChart.InitializeAsync(chartData, barChartOptions);
}
await base.OnAfterRenderAsync(firstRender);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<BarChart @ref="barChart" Height="300" Class="mb-4" />

@code {
private BarChart barChart = default!;
private BarChartOptions barChartOptions = default!;
private ChartData chartData = default!;

protected override void OnInitialized()
{
var colors = ColorBuilder.CategoricalTwelveColors;

var labels = new List<string> { "Chrome", "Firefox", "Safari", "Edge" };
var datasets = new List<IChartDataset>();

var dataset1 = new BarChartDataset()
{
Label = "Windows",
Data = new List<double> { 28000, 8000, 2000, 17000 },
BackgroundColor = new List<string> { colors[0] },
BorderColor = new List<string> { colors[0] },
BorderWidth = new List<double> { 0 },
};
datasets.Add(dataset1);

var dataset2 = new BarChartDataset()
{
Label = "macOS",
Data = new List<double> { 8000, 10000, 14000, 8000 },
BackgroundColor = new List<string> { colors[1] },
BorderColor = new List<string> { colors[1] },
BorderWidth = new List<double> { 0 },
};
datasets.Add(dataset2);

var dataset3 = new BarChartDataset()
{
Label = "Other",
Data = new List<double> { 28000, 10000, 14000, 8000 },
BackgroundColor = new List<string> { colors[2] },
BorderColor = new List<string> { colors[2] },
BorderWidth = new List<double> { 0 },
};
datasets.Add(dataset3);

chartData = new ChartData
{
Labels = labels,
Datasets = datasets
};

barChartOptions = new();
barChartOptions.Responsive = true;
barChartOptions.Interaction = new Interaction { Mode = InteractionMode.Y };
barChartOptions.IndexAxis = "y";

barChartOptions.Scales.X.Title.Text = "Visitors";
barChartOptions.Scales.X.Title.Display = true;

barChartOptions.Scales.Y.Title.Text = "Browser";
barChartOptions.Scales.Y.Title.Display = true;

barChartOptions.Scales.X.Stacked = true;
barChartOptions.Scales.Y.Stacked = true;

barChartOptions.Plugins.Title.Text = "Operating system";
barChartOptions.Plugins.Title.Display = true;
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await barChart.InitializeAsync(chartData, barChartOptions);
}
await base.OnAfterRenderAsync(firstRender);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<BarChart @ref="barChart" Height="300" Class="mb-4" />

@code {
private BarChart barChart = default!;
private BarChartOptions barChartOptions = default!;
private ChartData chartData = default!;

protected override void OnInitialized()
{
var colors = ColorBuilder.CategoricalTwelveColors;

var labels = new List<string> { "Chrome", "Firefox", "Safari", "Edge" };
var datasets = new List<IChartDataset>();

var dataset1 = new BarChartDataset()
{
Label = "Windows",
Data = new List<double> { 28000, 8000, 2000, 17000 },
BackgroundColor = new List<string> { colors[0] },
BorderColor = new List<string> { colors[0] },
BorderWidth = new List<double> { 0 },
};
datasets.Add(dataset1);

var dataset2 = new BarChartDataset()
{
Label = "macOS",
Data = new List<double> { 8000, 10000, 14000, 8000 },
BackgroundColor = new List<string> { colors[1] },
BorderColor = new List<string> { colors[1] },
BorderWidth = new List<double> { 0 },
};
datasets.Add(dataset2);

var dataset3 = new BarChartDataset()
{
Label = "Other",
Data = new List<double> { 28000, 10000, 14000, 8000 },
BackgroundColor = new List<string> { colors[2] },
BorderColor = new List<string> { colors[2] },
BorderWidth = new List<double> { 0 },
};
datasets.Add(dataset3);

chartData = new ChartData
{
Labels = labels,
Datasets = datasets
};

barChartOptions = new();
barChartOptions.Locale = "de-DE";
barChartOptions.Responsive = true;
barChartOptions.Interaction = new Interaction { Mode = InteractionMode.Y };
barChartOptions.IndexAxis = "y";

barChartOptions.Scales.X.Title.Text = "Visitors";
barChartOptions.Scales.X.Title.Display = true;

barChartOptions.Scales.Y.Title.Text = "Browser";
barChartOptions.Scales.Y.Title.Display = true;

barChartOptions.Scales.X.Stacked = true;
barChartOptions.Scales.Y.Stacked = true;

barChartOptions.Plugins.Title.Text = "Operating system";
barChartOptions.Plugins.Title.Display = true;
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await barChart.InitializeAsync(chartData, barChartOptions);
}
await base.OnAfterRenderAsync(firstRender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,24 @@
<SectionHeading Size="HeadingSize.H4" Text="Chart Types" PageUrl="@pageUrl" HashTagName="chart-types" />
<div class="mb-2">At this moment we are supporting four blazor chart types.</div>
<ol>
<li>Bar Chart</li>
<li>Doughnut Chart</li>
<li>Line Chart</li>
<li>Pie Chart</li>
<li><a href="/charts/bar-chart">Bar Chart</a></li>
<li><a href="/charts/doughnut-chart">Doughnut Chart</a></li>
<li><a href="/charts/line-chart">Line Chart</a></li>
<li><a href="/charts/pie-chart">Pie Chart</a></li>
</ol>

<Callout Type="CalloutType.Info">
We will add Bubble Chart, Polar Area Chart, Radar Chart, Scatter Chart, and Mixed Chart support in the subsequent versions.
</Callout>

<SectionHeading Size="HeadingSize.H4" Text="Charts Setup" PageUrl="@pageUrl" HashTagName="charts-setup" />
Refer <a href="http://getblazorbootstrap.com/docs/getting-started/blazor-webassembly#starter-template">starter template</a> for charts setup.

<SectionHeading Size="HeadingSize.H4" Text="Bar Chart" PageUrl="@pageUrl" HashTagName="bar-chart" />
<Demo Type="typeof(Charts_Demo_01_BarChart_Examples)" Tabs="true" />

<SectionHeading Size="HeadingSize.H4" Text="Doughnut Chart" PageUrl="@pageUrl" HashTagName="doughnut-chart" />
<Demo Type="typeof(Charts_Demo_03_DoughnutChart_Examples)" Tabs="true" />

<SectionHeading Size="HeadingSize.H4" Text="Line Chart" PageUrl="@pageUrl" HashTagName="line-chart" />
<Demo Type="typeof(Charts_Demo_04_LineChart_Examples)" Tabs="true" />

<SectionHeading Size="HeadingSize.H4" Text="Pie Chart" PageUrl="@pageUrl" HashTagName="pie-chart" />
<Demo Type="typeof(Charts_Demo_05_PieChart_Examples)" Tabs="true" />

@*<SectionHeading Size="HeadingSize.H4" Text="Colors" PageUrl="@pageUrl" HashTagName="colors" />
<Demo Type="typeof(Utils_Colors)" />*@
<div class="mb-3">
Refer <a href="/getting-started/blazor-webassembly">starter template</a> for charts setup.
</div>

@code {
private string pageUrl = "/charts";
private string title = "Blazor Charts";
private string description = "Blazor Bootstrap charts are well-designed chart components on top of Chart.js to visualize data. It contains a rich UI gallery of charts that cater to all charting scenarios. Its high performance helps render large amounts of data quickly.";
private string imageUrl = "https://i.imgur.com/FGgEMp6.jpg";
}
}
Loading

0 comments on commit bbf7d53

Please sign in to comment.