Profile Picture

Need help getting started with code

Posted By John Purvis 12 Years Ago
Author
Message
John Purvis
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 0, Visits: 1

Our ability to custom format the floatbars in this report, is a deciding factor on purchase of your SSRS addin product. We have been using Dundas chart controls in past, but with the purchase by Microsoft, this is no longer an option.

I like what I see in your product, but I do not see the expression builders we used to customize the report and see your product is much more dependent on custom code. While I have basic C# skills and we have C# developers, we need a jump start in coding.

I am need some code to allow for coloring of all floatbars based on combination of data field values, such as all records beging with C is Red, P is Blue, etc

Second code is to change the hatching of the floatbar based on a nonplotted data set value for each bar such as widebars for APPR, solid for Sch, narrowbars WAPPR.

I realy like the Timescale presentation, but need to expand the Time element to 6 hr periods and 1 hour periods, based on the overall date range. This need is secondary to the above

Last desire is ability for set font and maybe background of the Y axis groups,

Any questions, please feel free to call

Thanks John



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: 11 hours ago
Posts: 3,054, Visits: 4,009

Hi John,

First of all thank you for your interest in Nevron Chart for SSRS.

We're about to launch a new version very soon that has much more properties exposed as expressions - in fact all properties except filling and stroke will be specifiable by SSRS expressions as well. Custom code will of course be supported as well in the future and the API will remain the same so the new version will be 100% backward compatible.

Regarding your requirements:

1. I am need some code to allow for coloring of all floatbars based on combination of data field values, such as all records beging with C is Red, P is Blue, etc.

The following code snippet works with the float bar example shipped with the control:

using System;
using System.Collections.Generic;
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)
  {
   NChart chart = context.Document.Charts[0];
   
   Dictionary<string, NColorFillStyle> prefixToFill = new Dictionary<string, NColorFillStyle>();
   
   prefixToFill.Add("Documentation", new NColorFillStyle(Color.Red));
   prefixToFill.Add("Testing", new NColorFillStyle(Color.Green));
   
   foreach (NFloatBarSeries bar in chart.Series)
   {
    for (int i = 0; i < bar.Values.Count; i++)
    {
     string label = (string)bar.Labels[i];
     
     foreach (string prefix in prefixToFill.Keys)
     {
      if (label.StartsWith(prefix))
      {
       bar.FillStyles[i] = prefixToFill[prefix];
      }
     }
    }
   }
  }
 }
}

It dynamically assigns fill style to documentation and testing phase if they are present. Note that for this purpose you need to have labels in the values grouping of the float bar, even if they are marked as non visible.

2. Second code is to change the hatching of the floatbar based on a nonplotted data set value for each bar such as widebars for APPR, solid for Sch, narrowbars WAPPR.

This will be almost identical to the code above except that you'll have to embed more information on the label - if you sends us table data and report requirements we can provide a code snippet for that as well.

3. I realy like the Timescale presentation, but need to expand the Time element to 6 hr periods and 1 hour periods, based on the overall date range. This need is secondary to the above.

You mean you need to modify the date time step used to decorate the axis or the date time range of the axis?

Last desire is ability for set font and maybe background of the Y axis groups,

Currently you can only modify the first and second level of category grouping - this is done from Chart Area\Axes\Primary X\Scale\ - the first level grouping text properties are controlled from the "Label Text Style" and the second level and above from Group Label Text Styles. Currently you cannot control the background of the grouping, but that's also doable from code.

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

BTW you can request an evaluation online meeting at sales@nevron.com and we will check the report requirements and propose a relevant solution.



Best Regards,
Nevron Support Team



John Purvis
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 0, Visits: 1

 

Here is the label code info used to set bar and hatch

I like your use of dictionary

What I really need to code to set hatchstyle for a bar.

Thanks again.



Attachments
label code.jpg (282 views, 80.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: 11 hours ago
Posts: 3,054, Visits: 4,009

Hi John,

In general you can assign hatched filling to all chart elements - in the context of the example above if you modify the code to accept hatch styles the last two bars will be colored with a diagonal hatch style of white / to red or green:

using System;
using System.Collections.Generic;
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)
  {
   NChart chart = context.Document.Charts[0];
   
   Dictionary<string, NFillStyle> prefixToFill = new Dictionary<string, NFillStyle>();
   
   prefixToFill.Add("Documentation", new NHatchFillStyle(System.Drawing.Drawing2D.HatchStyle.BackwardDiagonal, Color.White, Color.Red));
   prefixToFill.Add("Testing", new NHatchFillStyle(System.Drawing.Drawing2D.HatchStyle.BackwardDiagonal, Color.White, Color.Green));
   
   foreach (NFloatBarSeries bar in chart.Series)
   {
    for (int i = 0; i < bar.Values.Count; i++)
    {
     string label = (string)bar.Labels[i];
     
     foreach (string prefix in prefixToFill.Keys)
     {
      if (label.StartsWith(prefix))
      {
       bar.FillStyles[i] = prefixToFill[prefix];
      }
     }
    }
   }
  }
 }
}

Regarding the color coding you sent us - it looks like Status do not influence the resulting code color right?



Best Regards,
Nevron Support Team



John Purvis
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 0, Visits: 1

Correct, status does not effect color, status effects hatch

Color is determined by other elements



John Purvis
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 0, Visits: 1

Using following code I am able to configure bar styles as needed.

Would like assistance on code to change Timeline axis to reflect hours, when Start and End dates are only 1-2 days

Thanks for your assistance so far, been good learning experience with your product


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


namespace MyNamespace
{

    /// <summary>

    /// Sample class

    /// </summary>

    public class MyClass

    {

        /// <summary>

        /// Main entry point

        /// </summary>

        /// <param name="context"></param>

        public static void RSMain(NRSChartCodeContext context)

        {

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

            HatchStyle hatch = new HatchStyle();

            Color backcolor = new Color();


            //Dictionary<string, NFillStyle> prefixToFill = new Dictionary<string, NFillStyle>();
           
            //prefixToFill.Add("Documentation", new NHatchFillStyle(hatch, Color.White, Color.CadetBlue));

            //prefixToFill.Add("Testing", new NHatchFillStyle(hatch, Color.White, Color.Green));
            

            foreach (NFloatBarSeries bar in chart.Series)

            {

                for (int i = 0; i < bar.Values.Count; i++)

                {

                    String label = (String)bar.Labels[i];

                    String wtype =  label.Substring(0, 2);

                    String priority = label.Substring(2, 1);

                    String rg = label.Substring(3, 1);

                    String appr = label.Substring(4, 3);

 

                   
                   
                  
                    if (appr=="APP")

                        hatch = HatchStyle.ForwardDiagonal;

                    else if (appr=="WSC")

                        hatch = HatchStyle.LightVertical;

                    else if (appr=="SCH")

                        hatch=HatchStyle.LightVertical;
                    else
                        hatch=HatchStyle.LightVertical;
                                  
                 
                 
                  if (wtype == "PM")
                    { backcolor = Color.Green; }
                   
                    else if (wtype =="OP")

                       { backcolor= Color.Blue;}

                    else if (wtype=="EN")

                        {backcolor = Color.Orange;}

                  else if (wtype == "CM")
                  { if (priority =="1")
                    {backcolor = Color.Red; }
     else
                     {backcolor = Color.Tan;}
                    }
 

                    bar.FillStyles[i] = new NHatchFillStyle(hatch, Color.White, backcolor);


                  }

            }I

        }

    }

}

 

 


 



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: 11 hours ago
Posts: 3,054, Visits: 4,009

Hi John,

That's relatively easy to acheive - the first step is to call the context.RecalcLayout method - which calculates all min maxes, axis ranges etc:

context.RecalcLayout();

then you need to check if the Y axis range is less than two days and modify it - for example:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Nevron;
using Nevron.Dom;
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)
  {
  
   NChart chart = context.Document.Charts[0];
   context.RecalcLayout();

   // get the ruler range and convert it to date time
   NRange1DD range = chart.Axis(StandardAxis.PrimaryY).Scale.RulerRange;
   DateTime startDate = DateTime.FromOADate(range.Begin);
   DateTime endDate = DateTime.FromOADate(range.End);
   TimeSpan twoDays = new TimeSpan(2, 0, 0, 0);

   // check if less than two days
   if ((endDate - startDate) <= twoDays)
   {
    // if less than two days = > modify scale to use two rows - first one with 6 hour step, second with 1 day step
    NRangeTimelineScaleConfigurator scale = chart.Axis(StandardAxis.PrimaryY).ScaleConfigurator as NRangeTimelineScaleConfigurator;
   
    if (scale != null)
    {
     scale.FirstRow.TickMode = TimelineScaleRowTickMode.Custom;
     scale.FirstRow.CustomStep = new NDateTimeSpan(6, NDateTimeUnit.Hour);
     scale.FirstRow.LabelValueFormatter = new NDateTimeValueFormatter("HH");

     scale.SecondRow.TickMode = TimelineScaleRowTickMode.Custom;
     scale.SecondRow.CustomStep = new NDateTimeSpan(1, NDateTimeUnit.Day);
     scale.SecondRow.LabelValueFormatter = new NDateTimeValueFormatter("dd");

     scale.ThirdRow.Visible = false;
    }
   }
  }
 }
}

applies a step of 6 six hours to the first level and 1 day for the second row in case the current Y axis range is less than two days.

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



Best Regards,
Nevron Support Team



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: 11 hours ago
Posts: 3,054, Visits: 4,009
Hi John,

Good news - we will include FX editors to nearly all chart/gauge properties (boolean, numeric, enum values, fills, strokes, shadows, text styles) in the upcomming major SSRS version. What is even better, we have implemented conditional data point appearance, which will allow to control all aspects of the fill and stroke of data points based on expressions.

Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic