Introduction
ReportMax is a free reporting tool for .NET developers. In this tutorial, I will show how to use the Chart control within ReportMax reports. Please note that as a pre-requisite for this tutorial, you need to read Tutorial 1 located here.
Background
This is a series of tutorials on how to use this nice free tool. This is one of the most wanted features: Using Charts inside Reports.
Using the Code
You will need ReportMax version 2.3 or higher.
Report Designer
- Create a C# WinForms project
- From the Project menu, select Add New Item
- Go to ReportMax files on the left, then Blank Report (Inch) on the right
- Enter report name "
MainReport
" and hit OK.
- In the report designer, expand the Page Header area
- Drag a Chart control from the Toolbox
- Name the chart control "
MainChart
"
- Save the Project
Report Viewer
Please note that the Chart control is basically a wrapper around Microsoft Chart control. So anything you can do with Microsoft Chart control, you can do with this control.
For a good reference for Microsoft Chart control, you can refer to this link.
Another important point to mention is that you can only program the chart control by code and not at design time.
- Add the
ReportMax
control on the Form.
- Set the
ReportFile
to the file path of "MainReport.rpm"
- Click on the
ReportMax
control. Go to Events tab in the Properties window.
- Double click
Report_PageHeader
event. This will create a new event handler and redirect you to the code page.
- At the top of the file, type the code:
- In the
Report_PageHeader
event handler, write the following code:
private void reportMaxViewer1_Report_PageHeader_Format(
CppMax.ReportMax.ReportMaxPage FilePage, ref bool bCancel)
{
ReportMaxChart MainChart = (ReportMaxChart)FilePage.FindControl("MainChart");
Chart chart1 = MainChart.GetChart();
ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
Title title1 = new System.Windows.Forms.DataVisualization.Charting.Title();
chart1.BackColor = System.Drawing.Color.FromArgb(
((System.Byte)(243)), ((System.Byte)(223)), ((System.Byte)(193)));
chart1.BackGradientStyle =
System.Windows.Forms.DataVisualization.Charting.GradientStyle.TopBottom;
chart1.BorderlineColor = System.Drawing.Color.FromArgb(
((System.Byte)(181)), ((System.Byte)(64)), ((System.Byte)(1)));
chart1.BorderlineDashStyle =
System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
chart1.BorderlineWidth = 2;
chart1.BorderSkin.SkinStyle =
System.Windows.Forms.DataVisualization.Charting.BorderSkinStyle.Emboss;
chartArea1.Area3DStyle.IsClustered = true;
chartArea1.Area3DStyle.Perspective = 10;
chartArea1.Area3DStyle.IsRightAngleAxes = false;
chartArea1.Area3DStyle.WallWidth = 0;
chartArea1.Area3DStyle.Inclination = 15;
chartArea1.Area3DStyle.Rotation = 10;
chartArea1.AxisX.LabelStyle.Font =
new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
chartArea1.AxisX.LineColor = System.Drawing.Color.FromArgb(
((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
chartArea1.AxisX.MajorGrid.LineColor = System.Drawing.Color.FromArgb(
((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
chartArea1.AxisY.LabelStyle.Font =
new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
chartArea1.AxisY.LineColor = System.Drawing.Color.FromArgb(
((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
chartArea1.AxisY.MajorGrid.LineColor = System.Drawing.Color.FromArgb(
((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
chartArea1.AxisY.MajorTickMark.Size = 0.6F;
chartArea1.BackColor = System.Drawing.Color.OldLace;
chartArea1.BackSecondaryColor = System.Drawing.Color.White;
chartArea1.BorderColor = System.Drawing.Color.FromArgb(
((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
chartArea1.Name = "Default";
chartArea1.Position.Auto = false;
chartArea1.Position.Height = 78F;
chartArea1.Position.Width = 88F;
chartArea1.Position.X = 5F;
chartArea1.Position.Y = 15F;
chartArea1.ShadowColor = System.Drawing.Color.Transparent;
chart1.ChartAreas.Add(chartArea1);
legend1.Alignment = System.Drawing.StringAlignment.Far;
legend1.IsTextAutoFit = false;
legend1.BackColor = System.Drawing.Color.Transparent;
legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
legend1.Name = "Default";
legend1.Position.Auto = false;
legend1.Position.Height = 14.23021F;
legend1.Position.Width = 19.34047F;
legend1.Position.X = 74.73474F;
legend1.Position.Y = 74.08253F;
chart1.Legends.Add(legend1);
chart1.Location = new System.Drawing.Point(16, 56);
chart1.Name = "chart1";
chart1.Palette = System.Windows.Forms.DataVisualization.Charting.ChartColorPalette.BrightPastel;
series1.BorderColor = System.Drawing.Color.FromArgb((
(System.Byte)(180)), ((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
series1.ChartType = SeriesChartType.Radar;
series1.Color = System.Drawing.Color.FromArgb(
((System.Byte)(220)), ((System.Byte)(65)), ((System.Byte)(140)), ((System.Byte)(240)));
series1.MarkerBorderColor = System.Drawing.Color.FromArgb(
((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
series1.MarkerSize = 9;
series1.Name = "Series1";
series1.ShadowOffset = 1;
series2.BorderColor = System.Drawing.Color.FromArgb(
((System.Byte)(180)), ((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
series2.ChartType = SeriesChartType.Radar;
series2.Color = System.Drawing.Color.FromArgb(((System.Byte)(220)),
((System.Byte)(252)), ((System.Byte)(180)), ((System.Byte)(65)));
series2.MarkerBorderColor = System.Drawing.Color.FromArgb(
((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
series2.MarkerSize = 9;
series2.Name = "Series2";
series2.ShadowOffset = 1;
chart1.Series.Add(series1);
chart1.Series.Add(series2);
chart1.TabIndex = 1;
title1.ForeColor = System.Drawing.Color.FromArgb(
((System.Byte)(26)), ((System.Byte)(59)), ((System.Byte)(105)));
title1.Font = new System.Drawing.Font("Trebuchet MS", 14.25F, System.Drawing.FontStyle.Bold);
title1.ShadowColor = System.Drawing.Color.FromArgb(
((System.Byte)(32)), ((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(0)));
title1.ShadowOffset = 3;
title1.Text = "Radar Chart";
chart1.Titles.Add(title1);
double[] yValues = { 65.62, 75.54, 60.45, 34.73, 85.42, 55.9, 63.6, 55.1, 77.2 };
double[] yValues2 = { 76.45, 23.78, 86.45, 30.76, 23.79, 35.67, 89.56, 67.45, 38.98 };
string[] xValues = { "France", "Canada", "Germany",
"USA", "Italy", "Spain", "Russia", "Sweden", "Japan" };
chart1.Series["Series1"].Points.DataBindXY(xValues, yValues);
chart1.Series["Series2"].Points.DataBindXY(xValues, yValues2);
chart1.Series["Series1"]["RadarDrawingStyle"] = "Area";
chart1.Series["Series2"]["RadarDrawingStyle"] = "Area";
chart1.Series["Series1"].BorderColor = Color.FromArgb(100, 100, 100);
chart1.Series["Series1"].BorderWidth = 1;
chart1.Series["Series2"].BorderColor = Color.FromArgb(100, 100, 100);
chart1.Series["Series2"].BorderWidth = 1;
chart1.Series["Series1"]["AreaDrawingStyle"] = "Polygon";
chart1.Series["Series2"]["AreaDrawingStyle"] = "Polygon";
chart1.Series["Series1"]["CircularLabelsStyle"] = "Circular";
chart1.Series["Series2"]["CircularLabelsStyle"] = "Circular";
MainChart.UpdateChart(chart1);
}
- Run the project.
Note that a chart type you can do with Microsoft Chart control can be done by ReportMaxChart
control.
First, you need to get the embedded Microsoft Chart control and modify it and at the end, call UpdateChart
to paint.
Points of Interest
The sample project contains a charting example. Please note that you can obtain data from any data source accessible from .NET and bind it to the chart.
Also, please refer to:
History