2

我有一个数据系列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) 

我正在尝试在这里创建一个帕累托图。

4

1 回答 1

1

API 在 SciChart v3.0 中发生了变化,但我们最近更新了一篇关于“标签提供程序 API 概述”的文章

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

您可以使用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}"/>

最后,如果您需要更多信息,这里有关于屏幕截图、打印和字符串轴标签的完整演练以及可下载的示例(更新为使用 API 的 v3.0)。

SciChart WPF 图表中的字符串轴

披露:我是SciChart WPF Charts的 MD 和所有者

于 2014-05-23T09:26:58.007 回答