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 チャートの文字列軸

開示:私はMDであり、SciChart WPF Chartsの所有者です

于 2014-05-23T09:26:58.007 に答える