【问题标题】:How to define the font color for a specific XLAbel[i] in teechart 7.12如何在 teechart 7.12 中为特定的 XLAbel[i] 定义字体颜色
【发布时间】:2013-01-18 16:45:29
【问题描述】:

如何为特定的XLabel[i] 定义Color

像这样,

Chart1.Series[0].XLabel[idxMP].FONT.Color := clBLue; 

但这不起作用。

我有 Delphi 7 和 Teechart 7.12

【问题讨论】:

  • 欢迎来到 StackOverflow。 不起作用 不能很好地描述发生在您身上的事情。它不编译?编译但在运行时引发异常?也不例外,但没有效果?您必须更准确地描述您的问题才能获得帮助。

标签: delphi delphi-7 teechart


【解决方案1】:

你有两个选择:

第一个是使用标准标签,应该如下所示:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Series1.FillSampleValues(20);
  Series2.FillSampleValues(20);
  Chart1.BottomAxis.OnDrawLabel := DrawBottomAxis;
end;

procedure TForm1.DrawBottomAxis(Sender:TChartAxis; var X,Y,Z:Integer; var Text:String;
  var DrawLabel:Boolean);
var
  lValue: Integer;
begin
  lValue := StrToIntDef(Text, -1);
  if lValue < 0 then
    Sender.LabelsFont.Color := clRed
  else
  if ((lValue mod 2) = 1) then
    Sender.LabelsFont.Color := clGreen
  else
    Sender.LabelsFont.Color := clYellow;
end;

第二个是使用自定义标签,如这段代码 sn-p:

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
    dt: TDateTime;
    myColor: TColor;
begin
  Chart1.AddSeries(TLineSeries.Create(Self));

  for i:=0 to 10 do
  begin
    dt:=Now + i;
    Chart1[0].AddXY(dt, random, DateToStr(dt));
  end;

  Chart1.Axes.Bottom.Items.Clear;

  for i:=0 to Chart1[0].Count-1 do
  begin
    if i mod 2 <> 0 then
      myColor:=clRed
    else
      myColor:=clBlack;

    Chart1.Axes.Bottom.Items.Add(Chart1[0].XValue[i], Chart1[0].Labels[i]).Format.Font.Color:=myColor;
  end;

  Chart1.Axes.Bottom.LabelsAngle:=90;
end;

【讨论】:

  • 这不是答案;这是对原始问题的评论。答案应该包含足够的内容以保持有效,即使引用的非现场链接由于某种原因不可用,在这种情况下你的链接将毫无意义。外部站点的链接作为附加参考非常有用,但答案应该是完全独立的。 (本网站的未来读者也无法搜索仅包含非现场链接的答案,试图找到他们遇到的问题的解决方案。)FAQ 有更多关于什么构成答案的详细信息。
  • @KenWhite 好的,我已经用我发布的链接中提到的代码更新了我的答案。
【解决方案2】:

非常感谢! 但只有这一行是正确的:(没有格式)

Chart1.Axes.Bottom.Items.Add(Chart1[0].XValue[i], Chart1[0].Labels[i]).Font.Color:=myColor;

但它现在可以正常工作了! 谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 1970-01-01
    • 2019-02-21
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    相关资源
    最近更新 更多