Setting Custom ColorSet from Managed Code

In this topic, we are going to explain how to set custom ColorSet from managed code.

 

For information about setting Silverlight project environment and creating Visifire Chart from managed code, please refer to the topic Managed Code Silverlight Sample.

 

Below is the code for creating custom ColorSet and adding it to the chart.

 

 

// Create Chart object

Chart chart = new Chart();

            

// Set Chart size

chart.Width = 500;

chart.Height = 300;

 

// Create ColorSet

ColorSet ct = new ColorSet();

 

ct.Id = "MyColorSet";

ct.Brushes.Add(new SolidColorBrush(Colors.Blue));

ct.Brushes.Add(new SolidColorBrush(Colors.Brown));

ct.Brushes.Add(new SolidColorBrush(Colors.Cyan));

ct.Brushes.Add(new SolidColorBrush(Colors.DarkGray));

ct.Brushes.Add(new SolidColorBrush(Colors.Gray));

ct.Brushes.Add(new SolidColorBrush(Colors.Green));

 

// Create new instance of ColorSets class

chart.ColorSets = new ColorSets();

 

// Add ColorSet to ColorSets collection

chart.ColorSets.Add(ct);

 

// Set ColorSet to chart

chart.ColorSet = "MyColorSet";

 

// Initialize new instance of Random class

Random rand = new Random();

 

// Create DataSeries object

DataSeries dataSeries = new DataSeries();

for (Int32 i = 0; i < 5; i++)

{

    // Create DataPoint object

    DataPoint dataPoint = new DataPoint();

 

    // Set DataPoint property

    dataPoint.YValue = rand.Next(10, 100);

 

    // Add DataPoint to DataPoints collection of DataSeries

    dataSeries.DataPoints.Add(dataPoint);

}

 

// Add DataSeries to Series collection of Chart

chart.Series.Add(dataSeries);

 

Below is the screen shot of the above chart.

 

 

Similarly you can create custom ColorSet in WPF also.

 

See Also: ColorSet