Steema Charts轴标签不可见

时间:2013-10-04 10:07:53

标签: delphi teechart

我正在使用查询来显示图表中的数据:

procedure TfrmUsage.ShowIndUsage(Sender: TObject);
var
  tmpQuery: TQuery;
  mTotal: integer;
  startMon: string;
  g1: TSeriesGroup;
begin
  Series7.Active:= False;
  Series0.Clear;
  Series1.Clear;
  Series2.Clear;
  Series0.Active:= True; // member 0
  Series1.Active:= True; // member 1
  Series2.Active:= True; // membership total
  tmpQuery:= TQuery.Create(nil);
  chrtUsage.Title.Text.Clear;
  with tmpQuery do begin
    DatabaseName:= Sessions.CurrentSession.Databases[0].DatabaseName;
    SessionName:= Sessions.CurrentSession.SessionName;
    SQL.Text:= 'select trim(fname)||" "||trim(lname) from asamembr ' + ' where cust_code = :custCode ' + ' and mbr_code = :mbrCode ';
    Params[0].AsString:= Self.fCustCode;
    Params[1].AsString:= '0'; // self.fmbrCode;
    Open;
    chrtUsage.Title.Text.add('Usage for Member ' + Fields[0].AsString + ' (yellow)');
    Close;
    Params[1].AsString:= '1'; // self.fmbrCode;
    Open;
    if not EOF then chrtUsage.Title.Text.add('Usage for Member ' + Fields[0].AsString + ' (red)')
    else Series1.Active:= False;

    chrtUsage.Title.Text.add('Usage for Membership (green)');
    Close;

    SQL.Text:= 'select extend(usage_date, year to month), mbr_code, count(*) from as   ambrhis ' +
      ' where asambrhis.cust_code = :custCode ' + ' and usage_date > today - 1 units year ' + ' group by 1,2 order by 1 ';
    Params[0].AsString:= Self.fCustCode;
    try
      Open;
      mTotal:= 0;
      startMon:= FormatDateTime('mmm/yyyy', Fields[0].AsDateTime);
      while not EOF do begin
        // chrtUsage.SeriesGroups.Items[0].Show;
        chrtUsage.Axes.Bottom.Labels:= True;
        chrtUsage.Axes.Bottom.LabelsSize:= 10;
        chrtUsage.BottomAxis.Visible:= True;
        chrtUsage.BottomAxis.Axis.Show;
        if startMon <> FormatDateTime('mmm/yyyy', Fields[0].AsDateTime) then begin
          Series2.add(mTotal, startMon);
          // Series2.Add
          if Series1.Active then // make sure we have all series bars
            if Series0.Count < Series1.Count then Series0.add(0, startMon)
            else if Series1.Count < Series0.Count then Series1.add(0, startMon);
          startMon:= FormatDateTime('mmm/yyyy', Fields[0].AsDateTime);
          mTotal:= 0;
        end;
        mTotal:= Fields[2].AsInteger + mTotal;
        if Fields[1].AsString = '0' then Series0.add(Fields[2].AsInteger, startMon)
        else if Fields[1].AsString = '1' then Series1.add(Fields[2].AsInteger, startMon);
        Next;
      end;
      Series2.add(mTotal, startMon);
      Close;
    finally
      tmpQuery.Free;
    end;
  end;
end;

此代码中,Variable startMon需要显示为底部轴的Label。请指导如何实现。 我已将标记设置为标签和值,然后在底部轴中我将标题设置为标记,或者我也尝试使用值,其他一个工作

1 个答案:

答案 0 :(得分:0)

您的代码中有一些未知的变量类型和初始化来测试它。但我可以解释一下它是如何运作的。

默认情况下,TChart使用带标签的第一个可见系列的标签。如果没有Seri​​es具有标签,则默认情况下会显示这些值。即:

uses Series, DateUtils;

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    startMon: string;
begin
  Chart1.View3D:=false;

  with Chart1.AddSeries(TBarSeries) as TBarSeries do
  begin
    for i:=1 to 5 do
    begin
      startMon:=FormatDateTime('mmm/yyyy', IncMonth(Today, i));
      Add(i, startMon);
    end;
  end;
end;

可以使用LabelStyle属性修改默认行为。即,要强制值显示在上面的示例中,您有一个带标签的系列:

Chart1.Axes.Bottom.LabelStyle:=talValue;