Click here to Skip to main content
15,881,248 members
Articles / Web Development / ASP.NET
Tip/Trick

.NET Reporting Tool Tutorial - 3

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
23 Apr 2013CPOL2 min read 25.3K   601   9   3
Using the Chart control in ReportMax

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

  1. Create a C# WinForms project
  2. From the Project menu, select Add New Item
  3. Go to ReportMax files on the left, then Blank Report (Inch) on the right
  4. Enter report name "MainReport" and hit OK.
  5. In the report designer, expand the Page Header area
  6. Drag a Chart control from the Toolbox
  7. Name the chart control "MainChart"
  8. 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.

  1. Add the ReportMax control on the Form.
  2. Set the ReportFile to the file path of "MainReport.rpm"
  3. Click on the ReportMax control. Go to Events tab in the Properties window.
  4. Double click Report_PageHeader event. This will create a new event handler and redirect you to the code page.
  5. At the top of the file, type the code:
  6. In the Report_PageHeader event handler, write the following code:
    C#
    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);
    
    // Populate series data
    // this could come from a data source
    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);
    
    // Set radar chart style
    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;
    
    // Set circular area drawing style
    chart1.Series["Series1"]["AreaDrawingStyle"] = "Polygon";
    chart1.Series["Series2"]["AreaDrawingStyle"] = "Polygon";
    
    // Set labels style
    chart1.Series["Series1"]["CircularLabelsStyle"] = "Circular";
    chart1.Series["Series2"]["CircularLabelsStyle"] = "Circular";
    
    MainChart.UpdateChart(chart1);
    }
  7. 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

  • Initial release

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) CppMax
Canada Canada
Check out our light-weight, easy to use and powerful Microsoft .net reporting tool www.cppmax.ca

Comments and Discussions

 
QuestionHow can I use the chart in the Detail area rather than the Page Header area Pin
yuanjieliu2-Sep-14 18:26
yuanjieliu2-Sep-14 18:26 
QuestionFurther explaination Pin
EnzeroX6-Aug-13 21:27
professionalEnzeroX6-Aug-13 21:27 
AnswerRe: Further explaination Pin
emadns11-Aug-13 9:45
emadns11-Aug-13 9:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.