How to plot MULTIPLE LineSeries on an OxyPlot chart?

前端 未结 3 1684
予麋鹿
予麋鹿 2021-02-07 14:51

I apologize for asking so many OxyPlot questions, but I seem to be really struggling with using the OxyPlot chart control.

My project is in WPF format so I was original

3条回答
  •  爱一瞬间的悲伤
    2021-02-07 15:45

    This is how I've created multi lines on an OxyPlot chart before, the key is creating a set of DataPoints for each series - called circlePoints & linePoints in the following example code, these are then bound to the CircleSeries and LineSeries:

    var xAxis = new DateTimeAxis
    {
        Position = AxisPosition.Bottom,
        StringFormat = Constants.MarketData.DisplayDateFormat,
        Title = "End of Day",
        IntervalLength = 75,
        MinorIntervalType = DateTimeIntervalType.Days,
        IntervalType = DateTimeIntervalType.Days,
        MajorGridlineStyle = LineStyle.Solid,
        MinorGridlineStyle = LineStyle.None,
    };
    
    var yAxis = new LinearAxis
    {
        Position = AxisPosition.Left,
        Title = "Value",
        MajorGridlineStyle = LineStyle.Solid,
        MinorGridlineStyle = LineStyle.None
    };
    
    var plot = new PlotModel();
    plot.Axes.Add(xAxis);
    plot.Axes.Add(yAxis);
    
    var circlePoints = new[]
    {
        new ScatterPoint(DateTimeAxis.ToDouble(date1), value1),
        new ScatterPoint(DateTimeAxis.ToDouble(date2), value2),
    };
    
    var circleSeries =  new ScatterSeries
    {
        MarkerSize = 7,
        MarkerType = MarkerType.Circle,
        ItemsSource = circlePoints
    };
    
    var linePoints = new[]
    {
        new DataPoint(DateTimeAxis.ToDouble(date1), value1),
        new DataPoint(DateTimeAxis.ToDouble(date2), value2),
    };
    
    var lineSeries = new LineSeries
    {
        StrokeThickness = 2,
        Color = LineDataPointColor,
        ItemsSource = linePoints
    };
    
    plot.Series.Add(circleSeries);
    plot.Series.Add(lineSeries);
    

提交回复
热议问题