2015-06-10 16 views
0

我有我想要設置包含系列標題和條的實際值的標記樣式的小節系列。這裏是我的代碼:TChart:獲取帶有系列標題的標記樣式及其值

procedure TFRDept.PopulateDeptChart; 
var 
    Loop ,YearIndex: integer; 
    DeptKey: String; 
    StartBar, TotalBar, EndBar : TBarSeries; 
begin 

    for Loop := 0 to FDeptList.Count -1 do 
    begin 
     DeptKey := FDeptList.ValueFromIndex[Loop]; 

     StartBar := GetInsertedBarSeries(DeptKey+'Start', 'Start', clGreen); 
     TotalBar := GetInsertedBarSeries(DeptKey+'Total', 'Total', clBlue); 
     EndBar := GetInsertedBarSeries(DeptKey+'End', 'End', clRed); 

     with Dataset do 
     begin 
      if Locate('o_deptaddressno',DeptKey,[]) then 
      begin 

       While (FieldByName('o_deptaddressno').AsString = DeptKey) and not eof do 
       begin 

        StartBar.AddXY(FieldByName('o_year').AsInteger, 
               FieldByName('o_totalstart').AsInteger, 
               FieldByName('o_year').AsString, 
               StartBar.Color); 


        {when adding series per year for each department - the bars are not one after the other} 
        //TotalBar := GetInsertedBarSeries(DeptKey+'Total'+FieldByName('o_year').AsString, siLang.GetTextOrDefault('IDS_TOTAL'), clBlue); 

        TotalBar.AddXY(FieldByName('o_year').AsInteger, 
                FieldByName('o_total').AsInteger, 
                FieldByName('o_year').AsString, 
                TotalBar.Color); 

        TotalBar.Title := FieldByName('o_total').AsString + ': '+ FDeptList.Names[Loop]; 
        TotalBar.Marks.Style := smsSeriesTitle; 
        TotalBar.Marks.ArrowLength := 50; 
        TotalBar.Marks.Callout.ArrowHead := ahSolid; 


        EndBar.AddXY(FieldByName('o_year').AsInteger, 
               FieldByName('o_totalEnd').AsInteger, 
               FieldByName('o_year').AsString, 
               EndBar.Color); 

        Next; 
       end; 
      end; 
     end; 
    end; 

    SetSeriesLegendProperties; 
end; 

function TFRDept.GetInsertedBarSeries(aName, aTitle: String; 
    aColor: TColor): TBarSeries; 
begin 
    Result := TBarSeries.Create(Self); 

    with Result do 
    begin 
     Name := 'Series' + aName; 
     Title := aTitle; 
     Color := aColor; 
     Marks.Style := smsValue; 
    end; 

    Chart1.AddSeries(Result); 
end; 

我的代碼生成以下欄但是對於藍條的數值未在商標獲得適當的值。

enter image description here 其實,我的目標是顯示每個系列酒吧(紅色,綠色和藍色)上方的各個部門。我甚至選擇了一種替代方法,試圖用'抽籤符號'來修改圖例,但事件沒有觸發。是否有可能在帶有複選框的樣式lsSeriesGroups的圖例中顯示符號?然後我還可以設置Totalbar:

Marks.Symbol.Visible := True; 

enter image description here

回答

2

這個使用此代碼工作正常,我:

uses Series; 

procedure TForm1.FormCreate(Sender: TObject); 
var i: Integer; 
begin 
    for i := 0 to 3 do 
    begin 
    Chart1.AddSeries(TBarSeries.Create(Self)).FillSampleValues(); 
    Chart1[i].Marks.Style:=smsValue; 
    Chart1[i].Title:='Series'+IntToStr(i); 
    Chart1[i].OnGetMarkText := Series1GetMarkText; 
    end; 
end; 

procedure TForm1.Series1GetMarkText(Sender: TChartSeries; 
    ValueIndex: Integer; var MarkText: String); 
begin 
    MarkText := MarkText + ' ' + Sender.Title; 
end; 

我甚至試圖修改選擇了另一種方式傳說 與'符號繪製',但事件沒有觸發。

你有意見嗎?例如:

Chart1.Legend.Symbol.OnDraw:=LegendDraw; 

有在一個完整的例子所有功能\歡迎\ Miscellanoeus \聯想\符號的OnDraw在功能於TeeChart控件的程序組演示使用!

是否有可能在樣式 lsSeriesGroups的複選框中顯示符號?然後我也可以設置Totalbar:

恐怕這不被支持。請隨時在Steema Software's bugzilla上添加您的功能請求。上面的代碼段產生這個圖表對我來說:

bars with value and title marks

+0

是。感謝負載。有用。我添加了第二張圖片來解釋我試圖顯示部門(系列組) – Veela

+0

@Veela ok的第二種可能性。恐怕這不可能。我已經回覆了一點點。 –