6.2.2 Example: Repors Containing Charts

Previous page Next page
  rev. 2007-12-04        

Creating reports which contain charts is as simple as creating the Chart(s) and adding them to the Report using the Charts property. A data table should also be created which can be used to group a chart to a specific subset of the reports data. For example in the following code block from the YtoYComparisonReport a data table is created which not only specifies the report and chart ids, but also includes the facility code, meter name and so on. This table is then used when the report is rendered to properly insert the correct chart for a given set of data. In the case of the YtoYComparisonReport the chart is associated with a specific facility code, meter name, meter component name, utility code and billing unit combination.

/// <summary>

/// Creates the charts used in the report

/// </summary>

/// <param name="data">The data table which contains the data needed for chart creation</param>

/// <param name="settings">The report settings</param>

/// <returns>The data table containing references to the charts</returns>

private DataTable CreateCharts(DataTable data, YtoYComparisonSettings settings)


 DateTime minYear = DateTime.MaxValue;

 DateTime maxYear = DateTime.MinValue;



 DataTable chartTable = new DataTable("");








 System.Collections.Hashtable hashtable = new System.Collections.Hashtable();

 foreach(DataRow row in data.Rows)


         Key key = new Key(row["FacilityCode"].ToString(),





         ManagingEnergy.Reports.Charts.Chart chart = null;

         // have we already created an item?



                 chart = base.NewChart(700,400);

                 chart.Plot.XAxisTitle = "Monthly Values";

                 chart.Plot.YAxisTitle =        Convert.ToString(row["UtilityType"])+" ($)";                                        



                         chart.Plot.XGridColor  = Plot.DefaultXGridColor;


                         chart.Plot.YGridColor = Plot.DefaultYGridColor;




                 DataRow chartRow = chartTable.NewRow();

                 chartRow["FacilityCode"] = row["FacilityCode"];

                 chartRow["MeterName"] = row["MeterName"];

                 chartRow["MeterComponentName"] = row["MeterComponentName"];

                 chartRow["UtilityCode"] = row["UtilityCode"];

                 chartRow["BillingUnits"] = row["BillingUnits"];

                 chartRow["ReportID"] = this.ID;

                 chartRow["ChartID"] = chart.ID;




                 chart = hashtable[key] as ManagingEnergy.Reports.Charts.Chart;


         DateTime currentRowDate = Convert.ToDateTime(row["StartDate"]).AddDays(1).Date;      

         DateTimeSeries series = chart.Plot.PlotData[currentRowDate.Year.ToString()] as DateTimeSeries;

         // add the graph data

         if(series == null)


                 series = new DateTimeSeries(currentRowDate.Year.ToString(),        new LinePlotter(Chart.GetColor(currentRowDate.Year),2.0F,true));                                        

                 series.DateFormat = "MMM";




         DateTime date = new DateTime(1900,currentRowDate.Month,1);

         series.Add(new DateTimeSeries.DateTimePoint(date,Convert.ToDouble(row["Quantity"])));                                



 // set the chart titles

 foreach(Chart chart in this.Charts)


         chart.Title = string.Format("YTD Comparison");



 return chartTable;



To show charts within a ComponentOne report, a Sub Report (rsubChartViewer) was created to streamline the process of loading and displaying a chart.

6.2.2_Example_Repors_Containin         ©2017 Managing Energy Inc.