2013-09-25 21 views
3

我正在使用Fast Reports 4.13.1。我需要在彙總樂隊上顯示多個圖表,並且我試圖在樂隊的OnBeforePrint事件處理程序中動態創建它們。問題是,當圖表正確創建時,系列不顯示我添加到它們的數據。這是我的OnBeforePrint事件:如何在代碼中創建TfrxChartView?

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; 

我在想什麼?有沒有TfrxChartView的任何屬性我應該設置我正在省略?

回答

1

您可能會使用XVal Series和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; 

//..... 
2

您的代碼缺少一些設置創建Series[0]之後:

  • Datatype屬性,以確定其數據是否來自dtDBDatadtBandDatadtFixedData
    • ,如果它是dtDBData,那麼你應該設置它的DataSet屬性
    • ,如果它是dtBandData,那麼你應該設置它DataBand屬性
  • XSourceYSource性能
  • 最後,其Active物業