lykrsl / googlechartsharp

Automatically exported from code.google.com/p/googlechartsharp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Friendlier version of SetDatasetColors

GoogleCodeExporter opened this issue · comments

I have to say that I don't like hex at all.
Therefore, I create a new version of SetDatasetColors which use Color array
as parameter instead of a series of hex string.

Well, this is the code, hope it useful for some one ^^ (me, at least).

/// <summary>
/// Set the color for each dataset, match colors to datasets by
/// specifying them in the same order the datasets were added to the
/// chart.
/// </summary>
/// <param name="datasetColors">an array of <see
cref="System.Drawing.Color"/></param>
public void SetDatasetColors(Color[] datasetColors)
{
    string[] colorHexArray = new string[datasetColors.Length];

    for (int i = datasetColors.Length - 1; i >= 0; i--)
    {
        colorHexArray[i] = ColorToHex(datasetColors[i]);
    }

    SetDatasetColors(colorHexArray);
}

/// <summary>
/// Convert <see cref="System.Drawing.Color"/> value to Hex value.
/// </summary>
/// <param name="color">A value of type <see cref="System.Drawing.Color"/>
which you want to convert in Hex value.</param>
/// <returns>Hex String</returns>
private string ColorToHex(Color color)
{
    return String.Format("{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
}

Original issue reported on code.google.com by hlam...@gmail.com on 5 Apr 2008 at 4:59