我正在尝试通过我的 CustomNumericLabelProvider 访问 viewModel 中的比例因子。
我不太确定最好的方法是什么,但我想如果我使用LabelProvider文档中显示的Init(IAxis parentAxis)方法,我可能能够通过父轴访问它。我已经尝试过了,但现在我收到一个错误消息,告诉我"There is no proper method for override"。
如果我注释掉Init()方法,CustomNumericLabelProvider 工作得很好(使用硬编码的比例因子)。
知道为什么我会收到此错误消息吗?或者还有什么好方法可以访问我的 viewModel 中的缩放因子?
注意:我还尝试将 viewModel 传递给标签提供程序的自定义构造函数(我可以使用 viewportManager 执行类似的操作),但这似乎不起作用。
这是代码(使用自定义构造函数,尽管没有它我会收到相同的错误消息)
public class CustomNumericLabelProvider : SciChart.Charting.Visuals.Axes.LabelProviders.NumericLabelProvider
{
// Optional: called when the label provider is attached to the axis
public override void Init(IAxis parentAxis) {
// here you can keep a reference to the axis. We assume there is a 1:1 relation
// between Axis and LabelProviders
base.Init(parentAxis);
}
/// <summary>
/// Formats a label for the axis from the specified data-value passed in
/// </summary>
/// <param name="dataValue">The data-value to format</param>
/// <returns>
/// The formatted label string
/// </returns>
public override string FormatLabel(IComparable dataValue)
{
// Note: Implement as you wish, converting Data-Value to string
var converted = (double)dataValue * .001 //TODO: Use scaling factor from viewModel
return converted.ToString();
// NOTES:
// dataValue is always a double.
// For a NumericAxis this is the double-representation of the data
}
}