3

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?

4

2 回答 2

3

您的代码在创建后缺少一些设置Series[0]

  • 它的Datatype属性,以确定它的数据是来自dtDBDatadtBandData还是dtFixedData
    • 如果是dtDBData,那么你应该设置它的DataSet属性
    • 如果是 dtBandData,那么你应该设置它的DataBand属性
  • XSourceYSource属性
  • 最后,它的Active属性
于 2013-09-25T14:44:29.010 回答
2

您可以使用 SeriesData 的 XValues 和 YValues 而不是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;

//.....
于 2013-09-25T15:56:18.460 回答