Profile Picture

Setting line/bar colours based on Series name

Posted By Rishi Ghose 11 Years Ago
Author
Message
Rishi Ghose
crazy Posted 11 Years Ago
View Quick Profile
Forum Newbie

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
Last Active: 11 Years Ago
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 (484 views, 14.00 KB)
Nevron Support
Posted 11 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: 1 days ago @ 1:38 AM
Posts: 3,054, Visits: 4,006

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
Posted 11 Years Ago
View Quick Profile
Forum Newbie

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
Last Active: 11 Years Ago
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
Posted 11 Years Ago
View Quick Profile
Forum Newbie

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
Last Active: 11 Years Ago
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
Posted 11 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: 1 days ago @ 1:38 AM
Posts: 3,054, Visits: 4,006
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
Posted 11 Years Ago
View Quick Profile
Forum Newbie

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
Last Active: 11 Years Ago
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);





Similar Topics


Reading This Topic