← All posts

Adding Charts to Your Reports


Majorsilence Reporting supports embedded charts that render inline on the report page alongside tables and text. Charts are bound to report datasets — the same dataset can drive both a summary chart and a detail table on the same page.

Chart Types

Eight chart types are available:

Type Best for
Column Comparing discrete categories (vertical bars)
Bar Horizontal version of column
Line Trends over time or continuous data
Area Line with filled area below
Pie Proportional breakdown of a whole
Doughnut Pie with a hollow centre
Scatter Individual data points on X/Y axes
Bubble Scatter with a third value for point size

Adding a Chart in the Designer

  1. Open your report in the designer.
  2. Right-click the report body and choose Insert → Chart.
  3. Select a chart type and click Next.
  4. Select the dataset the chart will read from.
  5. Map fields to the three roles:
    • Category (X axis) — the grouping dimension, e.g. {MonthName} or =Fields!Region.Value
    • Value (Y axis) — typically an aggregate, e.g. =Sum(Fields!Revenue.Value)
    • Series (optional) — splits bars/lines by colour, e.g. =Fields!Product.Value
  6. Click Finish, then resize and position the chart on the design surface.

Configuring Titles and Axes

Right-click the chart and choose Chart Properties to adjust:

  • Titles — static strings or expressions like ="Sales — " & Year({@ExecutionTime})
  • Legend — position (top, bottom, left, right) or hidden
  • Axis label format — uses standard .NET format strings:
C2      →  $1,234.56   (currency, 2 decimal places)
N0      →  1,235       (integer with thousand separator)
P1      →  42.3%       (percentage)

Rendering a Chart Report from Code

Once you have an .rdl file with a chart configured, rendering it is identical to any other report:

using Majorsilence.Reporting.Rdl;

RdlEngineConfig.RdlEngineConfigInit();

var baseDir = AppContext.BaseDirectory;
var rdlXml = await File.ReadAllTextAsync(Path.Combine(baseDir, "SalesChart.rdl"));

// Inject absolute DB path before Parse() — required for schema validation
rdlXml = rdlXml.Replace("sales.db", Path.Combine(baseDir, "sales.db"));

var parser = new RDLParser(rdlXml) { Folder = baseDir };
using var report = await parser.Parse();

if (report.ErrorMaxSeverity > 4)
{
    foreach (var err in report.ErrorItems)
        Console.Error.WriteLine(err);
    return;
}

await report.RunGetData(null);

// Charts render automatically in PDF and HTML — no extra config needed
var ofs = new OneFileStreamGen(Path.Combine(baseDir, "sales-report.pdf"), true);
await report.RunRender(ofs, OutputPresentationType.PDF);

Charts render automatically — no extra configuration is needed at the C# level. The chart definition lives entirely in the RDL file.

Combining a Chart and a Table

A common pattern is a summary chart above a detail table, both bound to the same dataset:

  1. Insert a chart at the top of the report body for the high-level picture.
  2. Add a table below it for the row-level detail.
  3. Point both to the same dataset.

The reporting engine runs the query once and feeds both items from the same data.

Tips

  • Set an explicit Width and Height on the chart item. Percentage-based sizes produce inconsistent output in PDF and TIFF exports.
  • For pie charts, keep category cardinality low (fewer than 8 slices). Many slices make labels overlap and the chart unreadable.
  • Line charts work best when the Category field is a date or sequential number with 10–200 data points.
  • To filter chart data without affecting a table on the same page, add a filter directly to the chart via Chart Properties → Filters rather than filtering the dataset.

Further Reading