Skip to main content

Passing Parameters to report chart datasource..

Comments

1 comment

  • Permanently deleted user

    Hi Chris,

    The Chart control in an RPX document doesn't get data bound the same way as other controls - there isn't a single DataField property that we can associate with the chart.  A chart may have multiple axes (series) to draw, which you can configure at design time, but that is not usually what you want to do.

    To set the chart control's data source at run time you can use some script.  Depending on the report, you may want to have a chart for every result in the data you have selected on the map; or, you may want to have a chart summarizing the data on the map.  In these examples I am using a pie chart (doughnut chart), since that only has one series.

    For one chart per row, use the Detail_Format event.  This example makes a new OleDbConnection at runtime to populate the chart with table data.:

    public void Detail1_Format() { DataDynamics.ActiveReports.ChartControl chart = (ChartControl)rpt.Sections["Detail1"].Controls["ChartControl1"]; ARControl layerName = rpt.Sections["detail"].Controls["Label1"]; string value = layerName.Value; // Go and get some data string cnnStr = "<Some valid OLEDB connection string to a data source>"; string sql = "SELECT * FROM TABLE WHERE CLAUSE=" + value; System.Data.OleDb.OleDbConnection dbconn = new System.Data.OleDb.OleDbConnection(cnnStr); System.Data.OleDb.OleDbDataAdapter oledbAdapter = new System.Data.OleDb.OleDbDataAdapter(sql, dbconn); dset = new DataSet("ChartData"); oledbAdapter.Fill(dset); // Bind the data from our report dataset to the chart's series. chart.Series[0].Points.DataBindXY( dset.Tables[0], dset.Tables[0].Columns[0].ColumnName, dset.Tables[0], dset.Tables[0].Columns[1].ColumnName); }

    For one chart summarizing the whole dataset, use the report's DataIntialize event to swap out the chart data and remove the report data:

    public void ActiveReport_DataInitialize() { DataSet dset = (DataSet)rpt.DataSource; DataDynamics.ActiveReports.ChartControl chart = (ChartControl)rpt.Sections["Detail1"].Controls["ChartControl1"]; DataDynamics.ActiveReports.Chart.Series s = new DataDynamics.ActiveReports.Chart.Series(); chart.Series.Add(s); s.Type = DataDynamics.ActiveReports.Chart.ChartType.Doughnut; // Bind the data from our report dataset to the chart's series. chart.Series[0].Points.DataBindXY( dset.Tables[0], dset.Tables[0].Columns[0].ColumnName, dset.Tables[0], dset.Tables[0].Columns[1].ColumnName); // Disconnect the report's original datasource. This stops the report from repeating for every row in the results table rpt.DataSource = null; }

     

    Regards,

    -Malcolm

    0

Please sign in to leave a comment.