2014-03-25 33 views
2

我有一個數據系列List<Tuple<string,double>>,我從中創建了一個XyDataSeries<double, double>。我使用以下LabelFormatterSciChart Column Series LabelFormatting

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) 

我想在這裏創建一個帕累託圖。

回答

1

的API已經在SciChart v3.0的改變,但我們這裏有最近更新的文章「Overview of the Label Provider API

我建議繼承LabelProviderBase因爲這實現了許多,你不必擔心接口的方法關於。在XAML

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 
    } 
} 

使用

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

最後,如果你需要更多的信息,對Screenshots, Printing and String Axis Labels here一個完整的演練與下載的樣本(:

可以按如下方式指定具有LabelProvider文本標籤更新爲使用API​​的v3.0)。

String Axis in SciChart WPF Charts

披露:我的SciChart WPF Charts

的MD和所有者