145 lines
4.6 KiB
Plaintext
145 lines
4.6 KiB
Plaintext
@page "/test"
|
|
|
|
<Heading Size="HeadingSize.Is1">Test</Heading>
|
|
|
|
<Button class="btn btn-info btn-sm" Clicked="@(async () => await HandleRedraw())">Redraw</Button>
|
|
|
|
<div class="row">
|
|
<div class="col-3">
|
|
<LineChart @ref="lineChart" TItem="double" OptionsObject="horizontalLineChartOptions" />
|
|
</div>
|
|
<div class="col-3">
|
|
<PieChart @ref="pieChart" TItem="double" OptionsObject="horizontalLineChartOptions" />
|
|
</div>
|
|
<div class="col-3">
|
|
<HorizontalBarChart @ref="barChartHoriz" TItem="double" OptionsObject="horizontalLineChartOptions" />
|
|
</div>
|
|
<div class="col-3">
|
|
<BarChart @ref="barChart" TItem="double" OptionsObject="horizontalLineChartOptions" />
|
|
</div>
|
|
</div>
|
|
|
|
@code {
|
|
PieChart<double> pieChart;
|
|
LineChart<double> lineChart;
|
|
HorizontalBarChart<double> barChartHoriz;
|
|
BarChart<double> barChart;
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
await HandleRedraw();
|
|
}
|
|
}
|
|
|
|
object horizontalLineChartOptions = new
|
|
{
|
|
//Title = new
|
|
//{
|
|
// Display = true,
|
|
// Text = "Line chart sample"
|
|
//},
|
|
//Scales = new
|
|
//{
|
|
// XAxes = new object[]
|
|
// {
|
|
// new {
|
|
// //ScaleLabel = new {
|
|
// //Display = true, LabelString = "value" },
|
|
// Stacked = true
|
|
// }
|
|
// }
|
|
//},
|
|
Tooltips = new
|
|
{
|
|
Mode = "nearest",
|
|
Intersect = false
|
|
},
|
|
Hover = new
|
|
{
|
|
Mode = "nearest",
|
|
Intersect = false
|
|
},
|
|
Legend = new
|
|
{
|
|
Display = true,
|
|
FullWidth = true
|
|
},
|
|
AspectRatio = 2.5
|
|
};
|
|
|
|
async Task HandleRedraw()
|
|
{
|
|
await pieChart.Clear();
|
|
await pieChart.AddLabelsDatasetsAndUpdate(Labels, GetPieChartDataset());
|
|
|
|
await lineChart.Clear();
|
|
await lineChart.AddLabelsDatasetsAndUpdate(Labels, GetLineChartDataset());
|
|
|
|
await barChart.Clear();
|
|
await barChart.AddLabelsDatasetsAndUpdate(Labels, GetBarChartDataset());
|
|
|
|
await barChartHoriz.Clear();
|
|
await barChartHoriz.AddLabelsDatasetsAndUpdate(Labels, GetHorizBarChartDataset());
|
|
}
|
|
|
|
PieChartDataset<double> GetPieChartDataset()
|
|
{
|
|
return new PieChartDataset<double>
|
|
{
|
|
Label = "# of randoms",
|
|
Data = RandomizeData(),
|
|
BackgroundColor = backgroundColors,
|
|
BorderColor = borderColors
|
|
};
|
|
}
|
|
|
|
LineChartDataset<double> GetLineChartDataset()
|
|
{
|
|
return new LineChartDataset<double>
|
|
{
|
|
Label = "# of randoms",
|
|
Data = RandomizeData(),
|
|
BackgroundColor = backgroundColors,
|
|
BorderColor = borderColors,
|
|
Fill = true,
|
|
PointRadius = 2,
|
|
BorderDash = new List<int> { }
|
|
};
|
|
}
|
|
|
|
BarChartDataset<double> GetBarChartDataset()
|
|
{
|
|
return new BarChartDataset<double>
|
|
{
|
|
Label = "# of randoms",
|
|
Data = RandomizeData(),
|
|
BackgroundColor = backgroundColors,
|
|
BorderColor = borderColors,
|
|
HoverBorderWidth = 5
|
|
};
|
|
}
|
|
BarChartDataset<double> GetHorizBarChartDataset()
|
|
{
|
|
return new BarChartDataset<double>
|
|
{
|
|
Label = "# of randoms",
|
|
Data = RandomizeData(),
|
|
BackgroundColor = backgroundColors,
|
|
BorderColor = borderColors,
|
|
HoverBorderWidth = 5
|
|
};
|
|
}
|
|
|
|
string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" };
|
|
List<string> backgroundColors = new List<string> { ChartColor.FromRgba(255, 99, 132, 0.2f), ChartColor.FromRgba(54, 162, 235, 0.2f), ChartColor.FromRgba(255, 206, 86, 0.2f), ChartColor.FromRgba(75, 192, 192, 0.2f), ChartColor.FromRgba(153, 102, 255, 0.2f), ChartColor.FromRgba(255, 159, 64, 0.2f) };
|
|
List<string> borderColors = new List<string> { ChartColor.FromRgba(255, 99, 132, 1f), ChartColor.FromRgba(54, 162, 235, 1f), ChartColor.FromRgba(255, 206, 86, 1f), ChartColor.FromRgba(75, 192, 192, 1f), ChartColor.FromRgba(153, 102, 255, 1f), ChartColor.FromRgba(255, 159, 64, 1f) };
|
|
|
|
List<double> RandomizeData()
|
|
{
|
|
var r = new Random(DateTime.Now.Millisecond);
|
|
|
|
return new List<double> { r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble(), r.Next(3, 30) * r.NextDouble() };
|
|
}
|
|
} |