2013-10-04 51 views
0

我使用要显示的图表中的数据的查询:Steema TCharts轴标签不可见

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需要被显示为标签为底轴。请指导如何完成。 我已将标记设置为Label和Value,然后在Bottom Axis中将标题设置为Marks,或者我也尝试过使用Value,但其中一个可以使用

+0

您应该真正看看您的缩进样式。如果你按下ctrl + d,IDE会为**你做**。哦,因为这个事实导致了范围的混淆。 – Johan

回答

0

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

默认情况下TChart使用标签中找到的第一个可见系列的标签。如果没有系列标签,仍默认显示这些值。即:

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;