1

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

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

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

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

xml是

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


}

谢谢,

巴克

4

0 回答 0