使用烛台时的空白图表

Blank chart when using candlesticks

尝试使用 Oxyplot 库绘制烛台图时,它是空的,尽管我已将模型分配给绘图视图。

var plotModel1 = new PlotModel { Title = "Large Data Set (wide window)" };

var timeSpanAxis1 = new DateTimeAxis { Position = AxisPosition.Bottom };
plotModel1.Axes.Add(timeSpanAxis1);
var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
plotModel1.Axes.Add(linearAxis1);
var n = 10000;
var items = HighLowItemGenerator.MRProcess(n).ToArray();
var series = new CandleStickSeries
{
    Color = OxyColors.Black,
    IncreasingColor = OxyColors.DarkGreen,
    DecreasingColor = OxyColors.Red,
    DataFieldX = "Time",
    DataFieldHigh = "H",
    DataFieldLow = "L",
    DataFieldOpen = "O",
    DataFieldClose = "C",
    TrackerFormatString =
                         "High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
    ItemsSource = items
};

timeSpanAxis1.Minimum = items[n - 200].X;
timeSpanAxis1.Maximum = items[n - 130].X;

linearAxis1.Minimum = items.Skip(n - 200).Take(70).Select(x => x.Low).Min();
linearAxis1.Maximum = items.Skip(n - 200).Take(70).Select(x => x.High).Max();

plotModel1.Series.Add(series);

timeSpanAxis1.AxisChanged += (sender, e) => AdjustYExtent(series, timeSpanAxis1, linearAxis1);

var controller = new PlotController();
controller.UnbindAll();
controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt);

plotView1.Model = plotModel1;

奇怪的是,我刚刚从 Oxyplot series example. I've also created minimal project 中复制了一些内容来描述问题。

HighLowItemGenerator 生成的对象的属性名称与 CandleStickSeries 定义中定义的不同。检查调试器中的 items 对象以查看它。也许样本有点过时了。解决方案是更改系列定义以使用正确的属性,这应该是这样的:

var series = new CandleStickSeries
{
      Color = OxyColors.Black,
      IncreasingColor = OxyColors.DarkGreen,
      DecreasingColor = OxyColors.Red,
      DataFieldX = "X",
      DataFieldHigh = "High",
      DataFieldLow = "Low",
      DataFieldOpen = "Open",
      DataFieldClose = "Close",
      TrackerFormatString =
                           "High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
      ItemsSource = items
};