Profile Picture

Custom colours of float bar bars

Posted By Clare Moore 13 Years Ago
Author
Message
Clare Moore
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

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

I have a float bar chart in SSRS 2008 R2, can I set the colour of a bar to the value of an expression? I want colours based on category group.

I really need a way of customising these depending on the data represented.

Also I have two category groups of data, and the outer category labels get truncated.  How do I overcome this?



Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746


Hi Clare,

Yes you can modify bar colors conditionally, including trough an expression. This is generally achieved by code - the following code shows how to dynamically modify the first bar in a float bar that has a label that starts with "Market Research":

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

namespace MyNamespace
{
 /// <summary>
 /// Sample class
 /// </summary>
 public class MyClass
 {
  /// <summary>
  /// Main entry point
  /// </summary>
  /// <param name="context"></param>
  public static void RSMain(NRSChartCodeContext context)
  {
   if (context.Document.Charts.Count == 0)
    return;
    
   NChart chart = context.Document.Charts[0];
   
   for (int i = 0; i < chart.Series.Count; i++)
   {
    NFloatBarSeries floatBar = chart.Series[i] as NFloatBarSeries;
    
    if (floatBar == null)
     continue;
     
    if (floatBar.Labels[i].ToString().StartsWith("Market Research"))
    {
     floatBar.FillStyles[i] = new NColorFillStyle(Color.Red);
    }
   }
  }
 }
}

The coloring and condition can be passed to the code by code parameters, which in turn can contain SSRS expression. Please post a some sample data along with the desired color for further comments.

Regarding:

Also I have two category groups of data, and the outer category labels get truncated.  How do I overcome this?

Can you post a screenshot?



Best Regards,
Nevron Support Team



Clare Moore
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

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

Thanks very much, I will give that code a try and let you know how it goes.

Here is a screen shot of cut off text, the beginning of my outer categories gets chopped off, if i make this axis on the right hand side, the end gets chopped off



Attachments
Activities.jpg (170 views, 15.00 KB)
Clare Moore
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

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

I tried out your code and I got an error:

"NChart Rendering Failed. Exception was: Exception has been thrown by the target of an invocation"

I changed the code to change the fillstyle of ALL floatbars and the code ran without error, however it also didnt work.  Can you tell me where i might be going wrong??  All my bars stayed the same colours from the custom palette.

using System;

using System.Drawing;

using Nevron.GraphicsCore;

using Nevron.Chart;

using Nevron.ReportingServices;

namespace MyNamespace

{

/// <summary>

/// Sample class

/// </summary>

public class MyClass

{

public static void RSMain(NRSChartCodeContext context)

{

if (context.Document.Charts.Count == 0)

return;

NChart chart = context.Document.Charts[0];

for (int i = 0; i < chart.Series.Count; i++)

{

NFloatBarSeries floatBar = chart.Series[i] as NFloatBarSeries;

if (floatBar == null)

continue;

floatBar.FillStyles[i] = new NColorFillStyle(Color.Red);

}

}

}

}



Clare Moore
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 22, Visits: 1
I managed to get my code working - how do I set the border colour in code also?  Currently my bars are filled with the correct colour but the border outline of each bar is still the colour of the custom colour palette?

Nevron Support
Posted 13 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)Supreme Being (4,329 reputation)

Group: Forum Members
Last Active: Last Year
Posts: 3,039, Visits: 3,746

Hi Clare,

You can change the border of float bar on a per bar basis using:

floatBar.BorderStyles[indexOfDataPoint] = new NStrokeStyle(1, Color.Red);

On a different note the code above contains a bug - the index "i" should not be used to index the float bar values & labels as it is used to loop trough the charts in the collection. Code should be reviced to:

if (floatBar == null)
     continue;

for (int j = 0; j < floatBar.Values.Count; j++)
{    
    if (floatBar.Labels[j].ToString().StartsWith("Market Research"))
    {
     floatBar.FillStyles[j] = new NColorFillStyle(Color.Red);
    }
}

That should not generate exceptions.



Best Regards,
Nevron Support Team



Clare Moore
Posted 13 Years Ago
View Quick Profile
Junior Member

Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)Junior Member (22 reputation)

Group: Forum Members
Last Active: 11 Years Ago
Posts: 22, Visits: 1
Thanks very much all sorted



Similar Topics


Reading This Topic