Completato pagina Test x grafici (da rivedere)
This commit is contained in:
@@ -2,12 +2,28 @@
|
||||
|
||||
<Heading Size="HeadingSize.Is1">Test</Heading>
|
||||
|
||||
<Button Clicked="@(async () => await HandleRedraw())">Redraw</Button>
|
||||
<Button class="btn btn-info btn-sm" Clicked="@(async () => await HandleRedraw())">Redraw</Button>
|
||||
|
||||
<LineChart @ref="lineChart" TItem="double" />
|
||||
<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)
|
||||
{
|
||||
@@ -17,11 +33,66 @@
|
||||
}
|
||||
}
|
||||
|
||||
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 lineChart.Clear();
|
||||
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()
|
||||
@@ -38,6 +109,29 @@
|
||||
};
|
||||
}
|
||||
|
||||
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) };
|
||||
@@ -46,6 +140,6 @@
|
||||
{
|
||||
var r = new Random(DateTime.Now.Millisecond);
|
||||
|
||||
return new List<double> { r.Next(3, 50) * r.NextDouble(), r.Next(3, 50) * r.NextDouble(), r.Next(3, 50) * r.NextDouble(), r.Next(3, 50) * r.NextDouble(), r.Next(3, 50) * r.NextDouble(), r.Next(3, 50) * r.NextDouble() };
|
||||
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() };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user