使用烛台时的空白图表

时间:2018-01-29 09:19:39

标签: c# oxyplot

当尝试使用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复制了一些东西。我还用所描述的问题创建了minimal project

1 个答案:

答案 0 :(得分:2)

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