How to apply palette from dropdown selected value in Blazor Charts?
This article explains how to apply palette from dropdown selected value in Blazor Charts.
Apply Palette from Dropdown Selected Value
Blazor Charts provides an option to apply palette from dropdown selected value.
To apply the palette to an accumulation chart based on the selected value, you need to assign colors for the dropdown list’s values and use the onchange event to apply the respective colors from the selected value.
The below code example demonstrates how to apply palette from dropdown selected value.
Index.razor
@using Syncfusion.Blazor.Charts
<select @onchange="Changed">
<option value="Bright">Bright</option>
<option value="GreyScale">GreyScale</option>
<option value="Excel">Excel</option>
</select>
<SfAccumulationChart Title=" Mobile Browser Statistics">
<AccumulationChartSeriesCollection>
<AccumulationChartSeries Palettes="@Colors" DataSource="@StatisticsDetails" XName="Browser" YName="Users" Name="Browser" />
</AccumulationChartSeriesCollection>
<AccumulationChartTooltipSettings Enable="true"></AccumulationChartTooltipSettings>
</SfAccumulationChart>
@code {
public String[]? Colors { get; set; }
public String[] Bright = new String[] { "#008000", "#0000FF", "#800080", "#00FF00", "#FF00FF", "#008080", "#FFFF00", "#808080", "#00FFFF", "#000080", "#800000", "#FF0000", "#808000", "#C0C0C0", "#FF6347", "#FFE4B5" };
public String[] GreyScale = new String[] { "#C8C8C8", "#BDBDBD", "#B2B2B2", "#A7A7A7", "#9C9C9C", "#919191", "#868686", "#7B7B7B", "#707070", "#656565", "#5A5A5A", "#4F4F4F", "#444444", "#393939", "#2E2E2E", "#232323" };
public String[] Excel = new String[] { "#9999FF", "#993366", "#FFFFCC", "#CCFFFF", "#660066", "#FF8080", "#0066CC", "#CCCCFF", "#000080", "#FF00FF", "#FFFF00", "#00FFFF", "#800080", "#800000", "#008080", };
public class Statistics
{
public string? Browser { get; set; }
public double Users { get; set; }
}
string color_pal = "Bright";
protected override void OnInitialized()
{
Colors = Bright;
}
public List<Statistics> StatisticsDetails = new List<Statistics>
{
new Statistics { Browser = "Chrome", Users = 37 },
new Statistics { Browser = "UC Browser", Users = 17 },
new Statistics { Browser = "iPhone", Users = 19 },
new Statistics { Browser = "Others", Users = 4 },
new Statistics { Browser = "Opera", Users = 11 },
new Statistics { Browser = "Android", Users = 12 },
};
public void Changed(ChangeEventArgs args)
{
color_pal = args.Value.ToString();
switch (color_pal)
{
case "Bright":
Colors = Bright.OrderBy(x => Guid.NewGuid()).ToArray();
break;
case "GreyScale":
Colors = GreyScale.OrderBy(x => Guid.NewGuid()).ToArray();
break;
case "Excel":
Colors = Excel.OrderBy(x => Guid.NewGuid()).ToArray();
break;
default:
Colors= Bright.OrderBy(x => Guid.NewGuid()).ToArray();
break;
}
}
}
The following screenshot illustrates the output of the code snippet.
Live sample for apply palette from dropdown selected value
Conclusion
I hope you enjoyed learning how to apply palette from dropdown selected value in Blazor Charts.
You can refer to our Blazor Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Blazor Chart example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!