void InitSymbol(Symbol s, string property, bool isShowMovingAverage = false) { s.Color = _Colors[IndexMemory % _Colors.Length]; IndexMemory++; HsbColor hsb = ColorEx.RgbToHsb(s.Color); s.MovingAverage = new MovingAverage() { Binding = property, Type = MovingAverageType.Simple, Period = 10, Visibility = isShowMovingAverage ? SeriesVisibility.Visible : SeriesVisibility.Hidden, }; s.MovingAverage.Style.StrokeWidth = 1; s.MovingAverage.Style.FillColor = s.MovingAverage.Style.StrokeColor = ColorEx.HsbToRgb(new HsbColor() { A = hsb.A, H = hsb.H, S = Math.Max(hsb.B / 2, 0), B = Math.Min(hsb.B * 2, 1) }); s.MovingAverage.DataSource = s.DataSource; s.Series = new C1.Win.Chart.Series() { Binding = property, Name = s.Code.ToUpper() }; s.Series.ChartType = ChartType.Line; s.Series.Style.StrokeWidth = 2; s.Series.Style.FillColor = Color.FromArgb(64, s.Color); s.Series.Style.StrokeColor = s.Color; s.Series.DataSource = s.DataSource; }
public static Color HsbToRgb(HsbColor hsbColor) { /* Gray (zero saturation) is a special case.We simply * set RGB values to HSB Brightness value and exit. */ // Gray: Set RGB and return if (hsbColor.S == 0.0) { return(Color.FromArgb((byte)(hsbColor.A * 255), (byte)(hsbColor.B * 255), (byte)(hsbColor.B * 255), (byte)(hsbColor.B * 255) )); } /* Now we process the normal case. */ var h = (hsbColor.H == 360) ? 0 : hsbColor.H / 60; //var i = (int)(Math.Truncate(h)); //var i = (int)(Math.Round(h)); if (double.IsNaN(h)) { return(Color.FromArgb((byte)(hsbColor.A * 255), (byte)(hsbColor.B * 255), (byte)(hsbColor.B * 255), (byte)(hsbColor.B * 255) )); } int i = Convert.ToInt32(Math.Floor(h)); var f = h - i; var p = hsbColor.B * (1.0 - hsbColor.S); var q = hsbColor.B * (1.0 - (hsbColor.S * f)); var t = hsbColor.B * (1.0 - (hsbColor.S * (1.0 - f))); double r, g, b; switch (i) { case 0: r = hsbColor.B; g = t; b = p; break; case 1: r = q; g = hsbColor.B; b = p; break; case 2: r = p; g = hsbColor.B; b = t; break; case 3: r = p; g = q; b = hsbColor.B; break; case 4: r = t; g = p; b = hsbColor.B; break; default: r = hsbColor.B; g = p; b = q; break; } // Set return value return(Color.FromArgb((byte)(hsbColor.A * 255), (byte)(r * 255), (byte)(g * 255), (byte)(b * 255) )); }
public static HsbColor RgbToHsb(Color rgbColor) { /* Hue values range between 0 and 360. All * other values range between 0 and 1. */ // Create HSB color object var hsbColor = new HsbColor(); // Get RGB color component values var r = (int)rgbColor.R; var g = (int)rgbColor.G; var b = (int)rgbColor.B; var a = (int)rgbColor.A; // Get min, max, and delta values double min = Math.Min(Math.Min(r, g), b); double max = Math.Max(Math.Max(r, g), b); double delta = max - min; /* Black (max = 0) is a special case. We * simply set HSB values to zero and exit. */ // Black: Set HSB and return if (max == 0.0) { hsbColor.H = 0.0; hsbColor.S = 0.0; hsbColor.B = 0.0; hsbColor.A = a / 255; return(hsbColor); } /* Now we process the normal case. */ // Set HSB Alpha value var alpha = (double)a; hsbColor.A = alpha / 255; // Set HSB Hue value if (r == max) { hsbColor.H = (g - b) / delta; } else if (g == max) { hsbColor.H = 2 + (b - r) / delta; } else if (b == max) { hsbColor.H = 4 + (r - g) / delta; } hsbColor.H *= 60; if (hsbColor.H < 0.0) { hsbColor.H += 360; } // Set other HSB values hsbColor.S = delta / max; hsbColor.B = max / 255; // Set return value return(hsbColor); }
private void InitializeTopChart() { if (_quoteData == null || !_quoteData.Any()) { return; } var maxVolume = _quoteData.Max(p => p.Volume); HsbColor hsb = ColorEx.RgbToHsb(_baseSeriesColor); financialChart1.BeginUpdate(); financialChart1.BindingX = "Date"; financialChart1.ToolTip.Active = false; financialChart1.AxisY.Position = Position.Right; financialChart1.AxisY.MajorGrid = false; financialChart1.AxisY.MinorGrid = false; financialChart1.AxisY.Format = null; financialChart1.Legend.Position = Position.None; ma = new MovingAverage() { Binding = Binding, Type = C1.Chart.MovingAverageType.Simple, Period = 10, Visibility = SeriesVisibility.Hidden }; ma.Style.StrokeWidth = 1; ma.Style.FillColor = ma.Style.StrokeColor = ColorEx.HsbToRgb(new HsbColor() { A = hsb.A, H = hsb.H, S = Math.Max(hsb.B / 2, 0), B = Math.Min(hsb.B * 2, 1) }); financialChart1.Series.Add(ma); fs = new Series() { Binding = Binding, Name = Symbol.ToUpper() }; fs.ChartType = ChartType.Line; fs.Style.StrokeWidth = 2; fs.Style.FillColor = Color.FromArgb(64, _baseSeriesColor); fs.Style.StrokeColor = _baseSeriesColor; financialChart1.Series.Add(fs); vs = new Series() { Binding = "Volume", AxisY = new C1.Win.Chart.Axis() { Max = maxVolume * 8 }, ChartType = C1.Chart.ChartType.Column }; vs.Style.FillColor = Color.FromArgb(255, 165, 0); vs.Style.StrokeColor = Color.FromArgb(255, 165, 0); financialChart1.Series.Add(vs); financialChart1.ChartType = FinancialChartType.Line; financialChart1.DataSource = _quoteData; financialChart1.EndUpdate(); financialChart1.MouseMove += FinancialChart1_MouseMove; }