Setting line/bar colours based on Series name


Author
Message
Rishi Ghose
Rishi Ghose
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)
Group: Forum Members
Posts: 0, Visits: 1
Hi,

I'm having trouble setting the colour of a line or bar in a chart based on the series name. For example, I have a chart that plots sales for 4 products categorised by month. Each product needs to have specific colour assigned to it. How can I code this in?

I've attached an example of the chart if it helps.

Many thanks in advance,
Rishi
Attachments
LineChart.png (512 views, 14.00 KB)
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K

Hi Rishi,

It looks like the attachment is missing from your post. Can you try posting it once again.

You can also take a look at the following KB topic: http://support.nevron.com/KB/a202/color-pie-chart-ssrs-according-to-color-each-row-the-dataset.aspx

Best Regards,
Nevron Support Team


Rishi Ghose
Rishi Ghose
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)
Group: Forum Members
Posts: 0, Visits: 1

Thank you, I've added the Attachment.

The pie chart example has only one series, is it possible for you to give me an example with more than one series?

Thanks,
Rishi
Rishi Ghose
Rishi Ghose
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)
Group: Forum Members
Posts: 0, Visits: 1

I came up with the following code for a Line Chart to solve the problem. However it does not seem to work, is there an obvious mistake on this?

using System;
using System.Drawing;
using System.Windows.Forms;
using Nevron.GraphicsCore;
using Nevron.Chart;
using Nevron.ReportingServices;

namespace MyNamespace
{
///
/// Sample class
///

public class MyClass
{
///
/// Main entry point
///

///
public static void RSMain(NRSChartCodeContext context)
{
NChart chart = context.Document.Charts[0];

for (int i = 0; i < chart.Series.Count; i++)
{
NSeriesBase series = chart.Series[i];

NLineSeries lineSeries = chart.Series[i] as NLineSeries;

if (series.Name.Contains("AGRALIX MONO")) {
lineSeries.FillStyle = new NColorFillStyle(Color.Red);
}

if (series.Name.Contains("CARDEX")) {
lineSeries.FillStyle = new NColorFillStyle(Color.Pink);
}

}
}
}
}
Nevron Support
Nevron Support
Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)Supreme Being (4.5K reputation)
Group: Administrators
Posts: 3.1K, Visits: 4.2K
Hi Rishi,

Yes - you need to modify the border style color for the line (fill is not used when line shape is line) - we tested with the following code and it was working OK:


using System;
using System.Drawing;
using System.Collections.Generic;
using Nevron.GraphicsCore;
using Nevron.Chart;
using Nevron.ReportingServices;

namespace MyNamespace
{
   ///
   /// Sample class
   ///

   public class MyClass
   {
      struct Name2Color
      {
         internal Name2Color(string name, Color color)
         {
            Name = name;
            Color = color;
         }
         
         internal string Name;
         internal Color Color;
      }
      ///
      /// Main entry point
      ///

      ///
      public static void RSMain(NRSChartCodeContext context)
      {
         NChart chart = context.Document.Charts[0];
         
         List name2ColorList =new List();
         
         name2ColorList.Add(new Name2Color("Revenue", Color.Blue));
         
         foreach (NLineSeries line in chart.Series)
         {
            foreach (Name2Color name2Color in name2ColorList)
            {
               if (line.Name.Contains(name2Color.Name))
               {
                  line.BorderStyle.Color = name2Color.Color;
                  break;
               }
            }
         }
      }
   }
}

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


Best Regards,
Nevron Support Team


Rishi Ghose
Rishi Ghose
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)
Group: Forum Members
Posts: 0, Visits: 1

I managed to figure this out, thanks to the pie chart example given above. The code above works for a bar chart..

For a line chart, please replace the line:

lineSeries.FillStyle = new NColorFillStyle(Color.Pink);

with

lineSeries.BorderStyle = new NStrokeStyle(2, Color.Pink);


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search