Hi Martyn,
Please find attached the sample report that shows a chart as percentages on the x axis. To replicate the report on your end you can follow these steps:
1. Create a table called [SampleTable] in the sample database (NRSVisionExamplesDB) distrubted with Nevron Chart for SSRS. Fill the following data in it:
AgeBand | BarWidth | Measure |
Under 16 | 0.0321559 | 11549 |
16 to 20 | 0.1518175 | 52440 |
21 to 24 | 0.183881 | 57004 |
25 to 34 | 0.3315085 | 85570 |
35 to 44 | 0.1695625 | 46703 |
45 to 54 | 0.08739768 | 25066 |
55 to 64 | 0.02772979 | 8421 |
65 + | 0.008125579 | 2061 |
2. Add the SampleReport1.rdl file to the examples solution shipped with the control and run it - you should get the following result:
A few explanations:
1. To achieve this chart we used the range series. It accepts four values x1, x2, y1, y2 definining a rectangle in scale space. Those four values map to the table as follows:
X1 = percentage
X2 = nothing
Y1 = 0
Y2 = Measure
In addition we also import the label value.
2. Then to assign X2 values we use the following code:
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];
if (chart.Series.Count == 0)
return;
NRangeSeries rangeSeries = chart.Series[0] as NRangeSeries;
if (rangeSeries == null)
return;
// compute total percentage
int count = rangeSeries.XValues.Count;
double total = 0;
for (int i = 0; i < count; i++)
{
total += (double)rangeSeries.XValues[i];
}
// then assign a value to x and x2
double xStart = 0;
double xEnd = 0;
rangeSeries.X2Values.Clear();
if (total <= 0)
return;
for (int i =0; i < count; i++)
{
xEnd = xStart + ((double)rangeSeries.XValues[i] / total);
rangeSeries.XValues[i] = xStart;
rangeSeries.X2Values.Add(xEnd);
xStart = xEnd;
}
// create a linear axis with custom labels to annotate the range series
NLinearScaleConfigurator scaleX = new NLinearScaleConfigurator();
scaleX.AutoLabels = false;
scaleX.MajorTickMode = MajorTickMode.CustomTicks;
for (int i = 0; i < count; i++)
{
NCustomValueLabel label = new NCustomValueLabel();
label.Text = (string)rangeSeries.Labels[i];
label.Value = ((double)rangeSeries.XValues[i] + (double)rangeSeries.X2Values[i]) / 2;
scaleX.CustomLabels.Add(label);
scaleX.CustomMajorTicks.Add((double)rangeSeries.X2Values[i]);
}
chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;
}
}
}
In a nutshell it does the following:
1. Compute the total for all percentages.
2. Assign X1, X2 for each bar in the series depending on it’s percentage and the total.
3. Create a custom value labels for the x axis to annotate those bars.
Hope this helps – let us know if you meet any problems or have any questions.
Best Regards,
Nevron Support Team