How to customize the Scale Values Based on your Business Logics in the .NET MAUI Linear Gauge?
The Syncfusion® .NET MAUI Linear Gauge (SfLinearGauge) allows you to customize scale values. This guide demonstrates how to customize the scale values based on your business logic.
XAML:
By utilizing the GenerateVisibleLabels, ValueToFactor, and FactorToValue callbacks, linear gauge enables you to show a series of values together with a custom scale based on your business logic.
<local:LinearGauge Minimum="1" Maximum="10000">
<gauge:SfLinearGauge.MarkerPointers>
<gauge:LinearShapePointer Value="1000" />
</gauge:SfLinearGauge.MarkerPointers>
</local:LinearGauge>
C#:
public class LinearGauge : SfLinearGauge
{
int labelsCount;
public override List<GaugeLabelInfo> GenerateVisibleLabels()
{
List<GaugeLabelInfo> labelInfos = new List<GaugeLabelInfo>();
int minimum = (int)LogBase(this.Minimum, 10);
int maximum = (int)LogBase(this.Maximum, 10);
for (int i = minimum; i <= maximum; i++)
{
double value = Math.Floor(Math.Pow(10, i));
GaugeLabelInfo label = new GaugeLabelInfo()
{
Value = value,
Text = value.ToString()
};
labelInfos.Add(label);
}
labelsCount = labelInfos.Count;
return labelInfos;
}
private double LogBase(double value, int baseValue)
{
return Math.Log(value) / Math.Log(baseValue);
}
public override double ValueToFactor(double value)
{
return LogBase(value, 10) / (labelsCount - 1);
}
public override double FactorToValue(double factor)
{
return Math.Pow(Math.E, factor * (labelsCount - 1) * Math.Log(10));
}
}
Output:
Conclusion
I hope you enjoyed learning how to customize the scale values based on your business logic in the .NET MAUI Linear Gauge (SfLinearGauge).
Refer to our .NET MAUI Linear Gauge feature tour page for other groundbreaking feature representations. You can also explore our .NET MAUI Linear Gauge documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Linear Gauge and other .NET MAUI components.
Please let us know in the comment section if you have any queries or require clarification. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!