0

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

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;

在此代码中,变量 startMon 需要显示为底部轴的标签。请指导如何实现。我已将标记设置为标签和值,然后在底部轴中将标题设置为标记,或者我也尝试使用值,两者都不起作用

4

1 回答 1

0

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

默认情况下,TChart 使用带有标签的第一个可见系列的标签。如果没有系列有标签,默认情况下,它仍然显示值。IE:

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;
于 2013-10-04T14:38:52.697 回答