Profile Picture

equivalent of SmoothPalette in a bar chart?

Posted By Keith Mason 12 Years Ago
Author
Message
Keith Mason
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 3, Visits: 1
Hello,

I am trying to create an effect where bars in a bar chart are colored based on their value, instead of on their series. The effect I am looking for is shown in 'oldbar.png', whereas what I've been able to make Chart for .NET do is shown in 'nevronbar.png'.

Note also the difference in the legend.

I have been able to see this type of effect with SmoothPalette in NSurfaceSeries, but I can't figure out how to do the same with NBarSeries.

What am I missing?

Thanks!

Attachments
oldbar.png (74 views, 24.00 KB)
nevronbar.png (78 views, 213.00 KB)
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 Keith,

In order to achieve this coloring you'll have to write some code that applies color per bar conditionally. For example consider the following code:

   NChart chart = nChartControl1.Charts[0];

   NBarSeries bar = new NBarSeries();

   Random rand = new Random();
   for (int i = 0; i < 10; i++)
   {
    bar.Values.Add(rand.Next(100));
   }

   for (int i = 0; i < bar.Values.Count; i++)
   {
    double value = (double)bar.Values[i];

    Color color = Color.FromArgb((int)(value / 100 * 255), 0, 0);

    bar.FillStyles[i] = new NColorFillStyle(color);
   }

   chart.Series.Add(bar);

It shows how to apply shades of red to a bar series - the bars closer to zero will have dark red color and the bars closer to 100 will be red.

Note that if you use style sheets you need to apply the bar conditional coloring after you apply the style sheet to the chart.

Hope this helps - let us know if you meet any problems or have any questions.



Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic