Profile Picture

Iterating through available colors in NColorFillStyle

Posted By Marcus McCallum 12 Years Ago
Author
Message
Niranjan Singh
Posted 12 Years Ago
View Quick Profile
Forum Member

Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)Forum Member (41 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 49, Visits: 179
Create a array of Colors and use that to get unique color for the series fillStyle.

Follow this approach, it is in C# but help you.

// color array example

Color[] PreDefinedSeriesColors = {
Color.Red, Color.Green, Color.Blue, Color.Brown, Color.BlueViolet,
Color.Crimson, Color.Cyan, Color.DarkRed
};

//Create Series and set fillStyle
int indexOfSeries;
NBarSeries bar = new NBarSeries();
chart.Series.Add(bar);
indexOfSeries = chart.Series.IndexOf(bar);
chartSeries.FillStyle = GetUniqueSeriesColor(indexOfSeries);


///
/// Get the unique color for the series
///

/// Added Series index in chart.Series[index]
/// Unique Series Color
private Color CheckAndGetUniqueSeriesColor(int currentChartSeriesIndex)
{
NCartesianChart chart = chartControl.Charts[0] as NCartesianChart;
Color seriesColor = PreDefinedSeriesColors[currentChartSeriesIndex];
List usedColors = new List();
if (currentChartSeriesIndex > 0)
{
for (int i = 0; i <= currentChartSeriesIndex - 1; i++)
{
usedColors.Add((chart.Series[i] as NSeries).FillStyle.GetPrimaryColor().ToColor().Name);
}

for (int i = 0; i <= currentChartSeriesIndex - 1; i++)
{
Color x = (chart.Series[i] as NSeries).FillStyle.GetPrimaryColor().ToColor();
Color y = NColor.FromString(PreDefinedSeriesColors[i].Name).ToColor();
if ( x != y && !usedColors.Exists( color => color.Equals(y.Name)))
{
seriesColor = PreDefinedSeriesColors[i];
break;
}
}
}
return seriesColor;
}


Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi Marcus,

You can use the following code to create a color table with relatively distinct colors - like so:

private Color[] CreateColorTable()
  {
   Array knownColors =
Enum.GetValues(typeof(KnownColor));
   Color[] colorTable = new Color[knownColors.Length];

   int index = 0;

   foreach (KnownColor knownColor in knownColors)
   {
    Color color =
Color.FromKnownColor(knownColor);
    colorTable[index++] = color;
   }

   return colorTable;
  }


And then fetch a color from this table using a method like:

  private Color FetchColor(Color[] colorTable, ref int
colorIndex)
  {
   if (colorIndex >= colorTable.Length)
    colorIndex = 0;

   return colorTable[colorIndex++];
  }

Let us know if you meet any problems.



Best Regards,
Nevron Support Team



Marcus McCallum
Posted 12 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 6 Years Ago
Posts: 29, Visits: 61

Hi,

 

I have a shapeseries array, whose size gets calculated whilst the code is running. I am looking for a way to automatically arrange for each member of the array to have a different color. How do I iterate through the colors?

 

I have also tried to just iterate through the color.fromargb, but for some reason this just gives the same color for every member of the array.

For i = 0 To ALLSegments.GetUpperBound(0)

ALLSegments(i).Name = "Segment " & i

Dim RedValue As Integer

RedValue = i + 20

If RedValue > 255 Then

RedValue = 255

End If

ALLSegments(i).FillStyle = New NColorFillStyle(Color.FromArgb(50, RedValue, 255, 255))

Next

 

Does anyone have any ideas on this?

Thanks,

Marcus





Similar Topics


Reading This Topic