gpt4 book ai didi

c# - SciChart 列系列标签格式

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:17 27 4
gpt4 key购买 nike

我有一个数据系列List<Tuple<string,double>>我从中创建了一个 XyDataSeries<double, double> .我使用以下 LabelFormatter .

public class SciChartCustomLabelFormatter : ILabelFormatter
{
private readonly string[] _xLabels;
public SciChartCustomLabelFormatter(string[] xLabels)
{
_xLabels = xLabels;
}
public void Init(IAxis parentAxis)
{
}
public void OnBeginAxisDraw()
{
}
public ITickLabelViewModel CreateDataContext(IComparable dataValue)
{
throw new NotImplementedException();
}
public ITickLabelViewModel UpdateDataContext(ITickLabelViewModel labelDataContext, IComparable dataValue)
{
throw new NotImplementedException();
}
public string FormatLabel(IComparable dataValue)
{
var index = (double)Convert.ChangeType(dataValue, typeof(double));
if (index >= 0 && index < _xLabels.Length)
return _xLabels[(int)index];

return index.ToString(CultureInfo.InvariantCulture);
}
public string FormatCursorLabel(IComparable dataValue)
{
var index = (double)Convert.ChangeType(dataValue, typeof(double));
if (index >= 0 && index < _xLabels.Length)
return _xLabels[(int)index];

return index.ToString(CultureInfo.InvariantCulture);
}
}

我想创建一个 FastColumnRenderableSeries

<sciChart:FastColumnRenderableSeries
x:Name="columnSeries" DataPointWidth="1"
SeriesColor="#A99A8A" Opacity="0.5"
XAxisId="BottomAxisId"
YAxisId="LeftAxisId"
DataSeries="{Binding Series}">
</sciChart:FastColumnRenderableSeries>

将字符串用作列系列的标签。

目前,我可以用 YAxis 清楚地显示值来显示系列。 但我如何使用标签格式化程序来显示 XAxis 字符串?我不知道我应该如何处理这些方法:

public ITickLabelViewModel CreateDataContext(IComparable dataValue) 

public ITickLabelViewModel UpdateDataContext(ITickLabelViewModel labelDataContext, IComparable dataValue) 

我正在尝试在此处创建 Pareto 图。

最佳答案

API 在 SciChart v3.0 中发生了变化,但我们在“Overview of the Label Provider API”上有一篇最近更新的文章'

我建议继承 LabelProviderBase,因为它实现了许多您不需要担心的接口(interface)方法。

您可以使用 LabelProvider 指定文本标签如下:

public class CustomLabelProvider : LabelProviderBase
{
/// <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)
{
return dataValue.ToString(); // TODO: Implement as you wish
}
/// <summary>Formats a label for the cursor, from the specified data-value passed in</summary>
/// <param name="dataValue">The data-value to format</param>
/// <returns>The formatted cursor label string</returns>
public override string FormatCursorLabel(IComparable dataValue)
{
return dataValue.ToString();// TODO: Implement as you wish
}
}

XAML 中的用法

<!-- Assumes you have declared the CustomLabelProvider as a static resource -->
<s:NumericAxis LabelProvider="{StaticResource local:CustomLabelProvider}"/>

最后,如果您需要更多信息,可以在 Screenshots, Printing and String Axis Labels here 上找到完整的演练。带有可下载示例(已更新为使用 API 的 v3.0)。

String Axis in SciChart WPF Charts

披露:我是 SciChart WPF Charts 的总经理和所有者

关于c# - SciChart 列系列标签格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22629000/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com