-
-
Couldn't load subscription status.
- Fork 92
Is there a way to set the tick don’t size on the bar chart? #1000
-
Is there a way to set the don’t size of the bar chart ticks (the numbers/labels on the data axes)?
I am able to set the don’t color using barchartoptions.Scale.Y!.Ticks=new ChartAxesTicks {Color="Red"}; and can change the other properties, but I can’t find a way of changing the font size of the ticks, and it’s causing some of the ticks to not render when doing a stacked bar chart.
I have found the size adjustments for most of the other components of the chart, but can’t find a way to set the ticks.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments
-
@ScriptKittiesShadow Thank you for using BlazorBootstrap. Please share a screenshot and sample code for better understanding.
Beta Was this translation helpful? Give feedback.
All reactions
-
I am basing this example off of the very nice documentation / Demos BlazorBootstrap provides, so hopefully it will look familiar.
The Base Bar chart looks very nice:
But when you add too many the tick labels start to get removed. For most things this is desired, but my production chart the labels are based on location, so I am wanting to make the labels smaller, so will show up without having to make the chart larger.
I figured out how to change the font color, but wasn't able to figure out a way to set the ChartAxesTicks size like I can most of the other elements. There is a TextStrokeWidth attribute, but I am not sure what that affects.
Here is the Code used for the control (Note: The Chart.js script is being called by the component instead of the global app.razor file so the script is only loaded when rendering the relevant controls. They have also been converted to local.)
Chart.Razor code
`
@rendermode InteractiveServer
<BarChart @ref="barChart" Width="500" Height="300" />
<script src="lib/chart.js/chart.umd.js"></script>`
Charts .CS code
`
public partial class ChartTest
{
@rendermode InteractiveServer
private BarChart barChart = default!;
private BarChartOptions barChartOptions = default!;
private ChartData chartData = default!;
protected override void OnInitialized()
{
var colors = ColorUtility.CategoricalTwelveColors;
var labels = new List<string> { "1", "2", "3", "4" ,"5","6","7","8","9","10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" };
var datasets = new List<IChartDataset>();
var dataset1 = new BarChartDataset()
{
Label = "Windows",
Data = new List<double?> { 28000, 8000, 2000, 17000, 8000, 2000, 17000, 8000, 2000, 17000, 28000, 8000, 2000, 17000, 8000, 2000, 17000, 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, 10000, 14000, 8000, 10000, 14000, 8000, 8000, 10000, 14000, 8000, 10000, 14000, 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, 10000, 14000, 8000, 10000, 14000, 8000, 28000, 10000, 14000, 8000, 10000, 14000, 8000, 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 BlazorBootstrap.Interaction { Mode = InteractionMode.Y };
barChartOptions.IndexAxis = "y";
barChartOptions.Scales.X!.Title = new ChartAxesTitle { Text = "Visitors", Display = true };
barChartOptions.Scales.Y!.Title = new ChartAxesTitle { Text = "Browser", Display = true };
barChartOptions.Scales.X.Stacked = true;
barChartOptions.Scales.Y.Stacked = true;
barChartOptions.Plugins.Title!.Text = "Operating system";
barChartOptions.Plugins.Title.Display = true;
//Change Tick Font color
barChartOptions.Scales.Y!.Ticks = new ChartAxesTicks { Color = "red" };
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
// pass the plugin name to enable the data labels
await barChart.InitializeAsync(chartData: chartData, chartOptions: barChartOptions, plugins: new string[] { });
}
await base.OnAfterRenderAsync(firstRender);
}
}
`
App.Razor code
`
<link rel="stylesheet" href="app.css" />
<link rel="stylesheet" href="ChartDemo.styles.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<HeadOutlet />
Beta Was this translation helpful? Give feedback.
All reactions
-
Should be fixed with #1083
Beta Was this translation helpful? Give feedback.