I'm using Fast Reports 4.13.1. I need to display a number of charts on my summary band, and I'm trying to dynamically create them in OnBeforePrint event handler of the band. The problem is, while the charts are created correctly, the series don't show the data I'm adding to them. Here's my OnBeforePrint event:

var
  dsSections,
  dsTests,
  dsHistory: TfrxDataSet;

  Chart: TfrxChartView;
  ChartCount: Integer;                                               
begin
  dsSections := Report.GetDataSet('frdTestSections');
  dsTests := Report.GetDataSet('frdResults');
  dsHistory := Report.GetDataSet('frdTestHistory');

  ChartCount := 0;
  dsSections.First;
  while not dsSections.Eof do
  begin
    dsTests.First;
    while not dsTests.Eof do
    begin
      if dsHistory.RecordCount > 0 then
      begin
        Chart := TfrxChartView.Create(rsHistory);
        Chart.Left := (ChartCount mod 2) * 8 + 1;
        Chart.Top := (ChartCount div 2) * 5 + 0.5;

        Chart.Width := 8;
        Chart.Height := 5;
        Chart.Chart.Title.Text.Text := dsTests.Value('Name');
        Chart.Chart.View3D := False;

        Chart.AddSeries(csLine);
        dsHistory.First;
        while not dsHistory.Eof do
        begin
          ShowMessage(dsTests.Value('Name') + #13#10 + IntToStr(dsHistory.RecNo + 1) + ' ' +dsHistory.Value('Result')); // this is for debugging only
          Chart.Series[0].Add(dsHistory.Value('Result'), IntToStr(dsHistory.RecNo + 1), clBlue);                                                                                                                                                                                                                 
          dsHistory.Next;
        end;                                                                                                       

        Inc(ChartCount);                                          
      end;
      dsTests.Next;
    end;
    dsSections.Next;
  end;                  
end;

What am I missing? Is there any property of TfrxChartView I should set that I'm ommiting?

有帮助吗?

解决方案 2

you might use XValues and YValues of SeriesData instead of Chart.Series[0].Add

//.....
  while not dsHistory.Eof do
  begin
    Chart.SeriesData[0].XValues := Chart.SeriesData[0].XValues + IntToStr(dsHistory.RecNo + 1) + ';';
    Chart.SeriesData[0].YValues := Chart.SeriesData[0].YValues + FloatToStr(dsHistory.Value('Result')) + ';';
    dsHistory.Next;
  end;

//.....

其他提示

Your code is missing some setup right after creating Series[0]:

  • its Datatype property, to establish whether its data comes from dtDBData, dtBandData or dtFixedData.
    • if it's dtDBData, then you should set its DataSet property
    • if it's dtBandData, then you should set its DataBand property
  • its XSource and YSource properties
  • and finally, its Active property
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top