Resizing bar width with parent and data set size to avoid overlapping


https://www.nevron.com/Forum/Topic5265.aspx
Print Topic | Close Window

By Wincy Mok - 13 Years Ago

Hello,

I'm new to Nevron and am having problems with the resizing of the width of the bars in a horizontal bar chart and wonder if anyone knows of a solution.

I'm trying to automatically generate a bar chart for a set of data that changes size all the time, so one day the data might only contain 10 bars, the next day it may contain 100s. I would like each bar to be distinct from one another, with no spaces between each bar, but no overlap either.

However when I extend the data set, the bars start overlapping, similarly, when I increase the chart size, the bars start spacing further and further apart.

I tried resizing the bars using parent percentage, but the addition of data points messes up the formatting as the percentage is static even though the number of bars have increased:

bar.BarWidth = new NLength(1.35f, NRelativeUnit.ParentPercentage);

 

I then tried taking the chart dimensions, and dividing it by the value range in the following formula:

range = chart.Height/((maxVal - minVal)/tickInterval

bar.BarWidth = new NLength((float)(range), NGraphicsUnit.Point);

but the chart height seems to remain static even if you resize the root panel (chart.width stays 55 even if I change panel size from 800x800 to 1500x1500).

Is there an easier way to resize the bar width in proportion to the data set size and the chart size that will avoid this spacing/overlap problem? Any insights would be appreciated.

Wincy

 

By Nevron Support - 13 Years Ago

Hi Wincy,

You can check out the dynamic sizing example (New_Layout_DynamicSize.rdl) shipped with 2011.Vol1 version. It shows how to automatically resize the chart based on the number of data points in the dataset.

In general this can be achieved in two ways:

1. From the designer go to Rendering\Size\Dynamic Width and specify an expression to determine the result size. In the example shipped with the control the expression is:

=Count(Fields!CountryName.Value) * 50

2. From code you need to touch context.RenderParameters.Width - for example:

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)
  {
   context.RenderParameters.Width = 2000;
  }
 }
}

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