Visual Studio 2012WebFormsOracleADO.NETVisual Studio 2010.NET4MySQLC# 4.0中级开发Visual StudioSQL Server.NETASP.NETC#
.NET 报表工具教程 - 3
在 ReportMax 中使用 Chart 控件
引言
ReportMax 是一个免费的 .NET 开发者报表工具。在本教程中,我将展示如何在 ReportMax 报表中使用图表控件。请注意,本教程需要预先阅读此处的教程 1。
背景
这是一系列关于如何使用这个不错的免费工具的教程。 这是最需要的功能之一:在报表中使用图表。
Using the Code
您需要 ReportMax 2.3 或更高版本。
报表设计器
- 创建一个 C# WinForms 项目
- 从“项目”菜单中,选择“添加新项
- 转到左侧的 ReportMax 文件,然后在右侧选择“空白报表(英寸)
- 输入报表名称“
MainReport
”,然后点击“确定”。 - 在报表设计器中,展开“页面页眉”区域
- 从工具箱中拖动一个图表控件
- 将图表控件命名为“
MainChart
” - 保存项目
报表查看器
请注意,图表控件基本上是 Microsoft 图表控件的包装器。 因此,您可以使用此控件执行 Microsoft 图表控件可以执行的任何操作。
有关 Microsoft 图表控件的良好参考,您可以参考此链接。
另一个需要提到的重要一点是,您只能通过代码而不是在设计时对图表控件进行编程。
- 在窗体上添加
ReportMax
控件。 - 将
ReportFile
设置为“MainReport.rpm”的文件路径 - 单击
ReportMax
控件。 转到“属性”窗口中的“事件”选项卡。 - 双击
Report_PageHeader
事件。 这将创建一个新的事件处理程序并将您重定向到代码页。 - 在文件顶部,输入代码
- 在
Report_PageHeader
事件处理程序中,编写以下代码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); }
- 运行项目。
请注意,可以使用 Microsoft 图表控件完成的图表类型也可以使用 ReportMaxChart
控件完成。
首先,您需要获取嵌入的 Microsoft 图表控件并对其进行修改,最后调用 UpdateChart
进行绘制。
关注点
示例项目包含一个图表示例。 请注意,您可以从 .NET 可以访问的任何数据源获取数据,并将其绑定到图表。
另请参阅
历史
- 首次发布