【问题标题】:TChart : Get mark style with series title together with its valueTChart:获取带有系列标题的标记样式及其值
【发布时间】:2015-06-10 07:43:41
【问题描述】:

我有条形系列,我想在其中设置包含系列标题和条形实际值的标记样式。这是我的代码:

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;

我的代码生成以下条,但蓝色条的值未在标记中获得适当的值。

实际上,我的目标是在每个系列的条(红色、绿色和蓝色)上方显示各自的部门。我什至选择了另一种方法,尝试使用“绘制符号”修改图例,但事件没有触发。是否有可能在带有复选框的样式 lsSeriesGroups 的图例中显示符号?然后我也可以设置 Totalbar :

Marks.Symbol.Visible :=  True;

【问题讨论】:

    标签: delphi-xe2 teechart


    【解决方案1】:

    使用此代码对我来说效果很好:

    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;
    

    我什至选择了另一种方式,尝试修改图例 'symbols on draw' 但事件没有触发。

    你做了吗?例如:

      Chart1.Legend.Symbol.OnDraw:=LegendDraw;
    

    在 TeeChart 程序组的功能演示中,All Features\Welcome!\Miscellanoeus\Legend\Symbol OnDraw 有一个完整的示例。

    有没有可能显示样式图例中的符号 带有复选框的lsSeriesGroups?然后我也可以设置 Totalbar :

    恐怕这不受支持。请随时在Steema Software's bugzilla 添加您的功能请求。上面的代码 sn-p 为我生成了这个图表:

    【讨论】:

    • 是的。感谢负载。有用。我添加了第二张图片来解释我尝试显示部门(系列组)的第二种可能性
    • @Veela 好的。那是不可能的,我害怕。我把我的回复延长了一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    相关资源
    最近更新 更多