WPF工具包图表 - 在条形图上绘制平滑曲线

时间:2013-09-30 22:22:23

标签: wpf charts wpftoolkit lineseries

我似乎无法在条形图上绘制平滑的曲线(在同一图表中)。我没有看到任何StackOverflow问题(但可能错过)。

无论如何,要做到这一点,我正在考虑将ColumnSeries用于具有LineSeries曲线的条形图。问题似乎是:

1)LineSeries中但不在ColumnSeries中的点始终显示在图表的末尾(即使X值介于ColumnSeries中的值之间)。我认为这些值之间的值可以用来使LineSeries曲线平滑。

2)LineSeries还控制X值之间的间距。我想要的只是LineSeries用于绘制条形之间的平滑曲线。事实上,LineSeries中有许多点使得条形很薄,应该很厚。换句话说,ColumnSeries理想地控制刻度线和条形厚度(而不是LineSeries)。

xaml是

    <Grid>
    <chartingToolkit:Chart x:Name="MainChart" HorizontalAlignment="Left" Margin="59,35,0,0" Title="Chart Title" VerticalAlignment="Top" Height="246" Width="405">
        <chartingToolkit:ColumnSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding BarCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
        <chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding LineCollection, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
    </chartingToolkit:Chart>
</Grid>

背后的代码是

    /// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window, INotifyPropertyChanged
{
    public MainWindow()
    {
        InitializeComponent();

        this.DataContext = this;

        // Add sample curve points
        LineCollection.Add(new KeyValuePair<double, double>(1, 11));
        LineCollection.Add(new KeyValuePair<double, double>(1.5, 18));
        LineCollection.Add(new KeyValuePair<double, double>(2, 22));
        LineCollection.Add(new KeyValuePair<double, double>(2.5, 35));
        LineCollection.Add(new KeyValuePair<double, double>(3, 42));

        // Primary bars being added
        BarCollection.Add(new KeyValuePair<double, double>(1, 10));
        BarCollection.Add(new KeyValuePair<double, double>(2, 20));
        BarCollection.Add(new KeyValuePair<double, double>(3, 40));
    }

    /// <summary>
    ///   Core event handler for the view model.
    /// </summary>
    public event PropertyChangedEventHandler PropertyChanged;

    /// <summary>
    ///   Routes property changed events.
    /// </summary>
    /// <param name="propertyName"> Defines the property name upon which routing is determined. </param>
    public void OnPropertyChanged(string propertyName)
    {
        PropertyChangedEventHandler handler = this.PropertyChanged;

        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    ObservableCollection<KeyValuePair<double, double>> barCollection = new ObservableCollection<KeyValuePair<double, double>>();

    public ObservableCollection<KeyValuePair<double, double>> BarCollection
    {
        get
        {
            return barCollection;
        }
        set
        {
            barCollection = value;
        }
    }

    ObservableCollection<KeyValuePair<double, double>> lineCollection = new ObservableCollection<KeyValuePair<double, double>>();

    public ObservableCollection<KeyValuePair<double, double>> LineCollection
    {
        get
        {
            return lineCollection;
        }
        set
        {
            lineCollection = value;
        }
    }


}

谢谢,

降压

0 个答案:

没有答案