/// <summary> /// Override this function to support palette colors drawing /// </summary> /// <param name="e">Paint value event arguments.</param> public override void PaintValue(PaintValueEventArgs e) { // Get palette colors array ChartColorPalette palette = (ChartColorPalette)e.Value; if (palette == ChartColorPalette.None) { base.PaintValue(e); } else { Color[] paletteColors = ChartPaletteColors.GetPaletteColors(palette); int numberOfcolors = paletteColors.Length; // Draw first colors of the palette if (numberOfcolors > 6) { numberOfcolors = 6; } int colorStep = paletteColors.Length / numberOfcolors; RectangleF rect = e.Bounds; rect.Width = (float)(e.Bounds.Width) / (float)(numberOfcolors); for (int i = 0; i < numberOfcolors; i++) { if (i == numberOfcolors - 1) { rect.Width = e.Bounds.Right - rect.X; } e.Graphics.FillRectangle(new SolidBrush(paletteColors[i * colorStep]), rect); rect.X = rect.Right; rect.Width = ((float)(e.Bounds.Width) / (float)(numberOfcolors)); } } }
/// <summary> /// Apply palette colors to the data series if UsePaletteColors property is set. /// </summary> internal void ApplyPaletteColors() { ChartColorPalette palette = this.Palette; // switch to default pallette if is none and custom collors array is empty. if (palette == ChartColorPalette.None && this.PaletteCustomColors.Length == 0) { palette = ChartColorPalette.BrightPastel; } // Get palette colors int colorIndex = 0; Color[] paletteColors = (palette == ChartColorPalette.None) ? this.PaletteCustomColors : ChartPaletteColors.GetPaletteColors(palette); foreach (Series dataSeries in _series) { // Check if chart area name is valid bool validAreaName = false; if (Chart != null) { validAreaName = Chart.ChartAreas.IsNameReferenceValid(dataSeries.ChartArea); } // Change color of the series only if valid chart area name is specified if (validAreaName) { // Change color of the series only if default color is set if (dataSeries.Color == Color.Empty || dataSeries.tempColorIsSet) { dataSeries.color = paletteColors[colorIndex++]; dataSeries.tempColorIsSet = true; if (colorIndex >= paletteColors.Length) { colorIndex = 0; } } } } }
public void ApplyPaletteColors() { if (this.Palette == ChartColorPalette.None && this.PaletteCustomColors.Length <= 0) { return; } int num = 0; Color[] array = (this.PaletteCustomColors.Length > 0) ? this.PaletteCustomColors : ChartPaletteColors.GetPaletteColors(this.colorPalette); foreach (Series item in this.series) { bool flag = false; if (item.ChartArea.Length > 0) { ChartImage chartImage = (ChartImage)this.serviceContainer.GetService(typeof(ChartImage)); if (chartImage != null) { foreach (ChartArea chartArea in chartImage.ChartAreas) { if (chartArea.Name == item.ChartArea) { flag = true; break; } } if (!flag && item.ChartArea == "Default" && chartImage.ChartAreas.Count > 0) { flag = true; } } } if (flag && (item.Color == Color.Empty || item.tempColorIsSet)) { item.color = array[num++]; item.tempColorIsSet = true; if (num >= array.Length) { num = 0; } } } }
private void ApplyPaletteColors() { ChartColorPalette palette = series.Palette; DataManager dataManager = (DataManager)series.serviceContainer.GetService(typeof(DataManager)); if (palette == ChartColorPalette.None) { palette = dataManager.Palette; } if (palette == ChartColorPalette.None && dataManager.PaletteCustomColors.Length == 0) { return; } int num = 0; Color[] array = (dataManager.PaletteCustomColors.Length != 0) ? dataManager.PaletteCustomColors : ChartPaletteColors.GetPaletteColors(palette); ArrayList arrayList = new ArrayList(series.Points); arrayList.AddRange(supplementalSeries.Points); foreach (DataPoint item in arrayList) { if (!item.Empty && !double.IsNaN(item.YValues[0]) && (!item.IsAttributeSet(CommonAttributes.Color) || item.tempColorIsSet)) { item.Color = array[num]; num++; if (num >= array.Length) { num = 0; } } } }