private Dictionary <string, Color> GetGradientDictColor(BiColorGradientTheme gradientTheme) { Dictionary <string, Color> result = new Dictionary <string, Color>(); double minValue = gradientTheme.MinValue; double maxValue = gradientTheme.MaxValue; double interval = (maxValue - minValue) / 5; double leftVal = 0; double rightVal = 0; if (interval == 0) { interval = 1; } for (int index = 0; index <= 4; index++) { leftVal = minValue + interval * index; rightVal = minValue + interval * (index + 1); string range = string.Format(" {0}~{1}", leftVal.ToString(), rightVal.ToString()); Color color = new Color(); color = gradientTheme.GetColorByValue(minValue + index * interval); result.Add(range, color); } return(result); }
public Color GetColorByValue(double value) { double[] values = _stops.Keys.ToArray(); if (value < values.First()) { return(_stops.First().Value); } else { for (int i = 0; i < values.Length - 1; i++) { double a = values[i]; double b = values[i + 1]; if (value >= a && value < b) { BiColorGradientTheme bcgm = new BiColorGradientTheme { MinValue = a, MaxValue = b, MinColor = _stops[a], MaxColor = _stops[b] }; return(bcgm.GetColorByValue(value)); } } return(_stops.Last().Value); } }