Registering DataTable with child Tables in code

edited September 2021 in FastReport .NET

Hi all,

I'm trying to use multiple Data Tables in a single MSChart. To do this I made a parent DataTable to contain all my other tables:

from ReportTemplate.frx:

<TableDataSource Name="AllData" ReferenceName="AllData" DataType="System.Int32" Enabled="true">
      <TableDataSource Name="A" ReferenceName="AllData.A" DataType="System.Int32" Enabled="true">
        <Column Name="X" DataType="System.Double"/>
        <Column Name="Y" DataType="System.Double"/>
      </TableDataSource>
      <TableDataSource Name="B" ReferenceName="AllData.B" DataType="System.Int32" Enabled="true">
        <Column Name="X" DataType="System.Double"/>
        <Column Name="Y" DataType="System.Double"/>
      </TableDataSource>
</TableDataSource>

When I register Data non-hierachical Data, I do it as follows:

//...
DataSet dataSet = new DataSet();

DataTable dataA = new DataTable();
DataTable dataB = new DataTable();
dataA.TableName = "A";
dataB.TableName = "B";

DataTable[] dataArray = new DataTable[]{ dataA, dataB, };


foreach (var table in dataArray)
{
    table.Columns.Add("X", typeof(double));
    table.Columns.Add("Y", typeof(double));
}

dataSet.Tables.AddRange(dataArray);

// Add rows to the tables containing the desired data
//...

report.RegisterData(dataSet, "DataSet");

//...

How can I register the table "AllData" that contains "A" and "B"?

Comments

  • Hello!

    Place all the required DataTables (A, B, etc.) into a single DataSet, call `report.RegisterData(dataSet)` and enable all the tables: `report.GetDataSource(‘A’).Enabled = true; report.GetDataSource(‘B’).Enabled = true;`.

    Bind the Chart1.DataSource itself to the main table A (for Series[0]).

    Fill in the additional series (Series[1] and so on) with data points manually in the Chart1_BeforePrint handler (be sure to cast (MSChartObject)sender):

    private void Chart1_BeforePrint(object sender, EventArgs e)
    {
      var ch = (MSChartObject)sender;
      var dsB = Report.GetDataSource(‘B’);
      dsB.Init();
      ch.Chart.Series[1].Points.Clear();
      while (dsB.HasMoreRows)
      {
        ch.Chart.Series[1].Points.AddXY(
          Convert.ToDouble(Report.GetColumnValue(‘B.X’)),
          Convert.ToDouble(Report.GetColumnValue(‘B.Y’)));
        dsB.Next();
      }
    }
    
This discussion has been closed.