/// <summary> /// Creates the volume series. /// </summary> /// <returns>The volume series.</returns> /// <param name="title">Title.</param> /// <param name="style">Style.</param> /// <param name="n">N.</param> /// <param name="natural">If set to <c>true</c> natural.</param> /// <param name="transposed">If set to <c>true</c> transposed.</param> private static Example CreateVolumeSeries( string title, VolumeStyle style, int n = 10000, bool natural = false) { var pm = new PlotModel { Title = title }; var series = new VolumeSeries { PositiveColor = OxyColors.DarkGreen, NegativeColor = OxyColors.Red, PositiveHollow = false, NegativeHollow = false, VolumeStyle = style, Title = "VolumeSeries", }; // create bars foreach (var bar in OhlcvItemGenerator.MRProcess(n)) { series.Append(bar); } // create visible window var Istart = n - 200; var Iend = n - 120; var Xmin = series.Items[Istart].X; var Xmax = series.Items[Iend].X; // setup axes var timeAxis = new DateTimeAxis { Position = AxisPosition.Bottom, Minimum = Xmin, Maximum = Xmax }; var volAxis = new LinearAxis { Position = AxisPosition.Left, StartPosition = 0.0, EndPosition = 1.0, Minimum = natural ? double.NaN : 0, Maximum = natural ? double.NaN : 10000 }; switch (style) { case VolumeStyle.Combined: case VolumeStyle.Stacked: pm.Axes.Add(timeAxis); pm.Axes.Add(volAxis); break; case VolumeStyle.PositiveNegative: volAxis.Minimum = natural ? double.NaN : -10000; pm.Axes.Add(timeAxis); pm.Axes.Add(volAxis); break; } pm.Series.Add(series); var controller = new PlotController(); controller.UnbindAll(); controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt); return(new Example(pm, controller)); }
/// <summary> /// Creates the candle stick and volume series example. /// </summary> /// <returns>The candle stick and volume series example.</returns> /// <param name="title">Title.</param> /// <param name="style">Style.</param> /// <param name="n">N.</param> /// <param name="naturalY">If set to <c>true</c> natural y.</param> /// <param name="naturalV">If set to <c>true</c> natural v.</param> private static Example CreateCandleStickAndVolumeSeriesExample( string title, VolumeStyle style, int n = 10000, bool naturalY = false, bool naturalV = false) { var pm = new PlotModel { Title = title }; var series = new CandleStickAndVolumeSeries { PositiveColor = OxyColors.DarkGreen, NegativeColor = OxyColors.Red, PositiveHollow = false, NegativeHollow = false, SeparatorColor = OxyColors.Gray, SeparatorLineStyle = LineStyle.Dash, VolumeStyle = style }; // create bars foreach (var bar in OhlcvItemGenerator.MRProcess(n)) { series.Append(bar); } // create visible window var Istart = n - 200; var Iend = n - 120; var Ymin = series.Items.Skip(Istart).Take(Iend - Istart + 1).Select(x => x.Low).Min(); var Ymax = series.Items.Skip(Istart).Take(Iend - Istart + 1).Select(x => x.High).Max(); var Xmin = series.Items[Istart].X; var Xmax = series.Items[Iend].X; // setup axes var timeAxis = new DateTimeAxis { Position = AxisPosition.Bottom, Minimum = Xmin, Maximum = Xmax }; var barAxis = new LinearAxis { Position = AxisPosition.Left, Key = series.BarAxisKey, StartPosition = 0.25, EndPosition = 1.0, Minimum = naturalY ? double.NaN : Ymin, Maximum = naturalY ? double.NaN : Ymax }; var volAxis = new LinearAxis { Position = AxisPosition.Left, Key = series.VolumeAxisKey, StartPosition = 0.0, EndPosition = 0.22, Minimum = naturalV ? double.NaN : 0, Maximum = naturalV ? double.NaN : 5000 }; switch (style) { case VolumeStyle.None: barAxis.Key = null; barAxis.StartPosition = 0.0; pm.Axes.Add(timeAxis); pm.Axes.Add(barAxis); break; case VolumeStyle.Combined: case VolumeStyle.Stacked: pm.Axes.Add(timeAxis); pm.Axes.Add(barAxis); pm.Axes.Add(volAxis); break; case VolumeStyle.PositiveNegative: volAxis.Minimum = naturalV ? double.NaN : -5000; pm.Axes.Add(timeAxis); pm.Axes.Add(barAxis); pm.Axes.Add(volAxis); break; } pm.Series.Add(series); if (naturalY == false) { timeAxis.AxisChanged += (sender, e) => AdjustYExtent(series, timeAxis, barAxis); } var controller = new PlotController(); controller.UnbindAll(); controller.BindMouseDown(OxyMouseButton.Left, PlotCommands.PanAt); return(new Example(pm, controller)); }