在xy值图中更改x轴标签

时间:2019-08-12 08:50:36

标签: delphi plot label teechart

我正在尝试在Delphi中更改xyplot上的标签。除了在数据点旁边显示标签之外,x轴还需要一个标签(当前它显示整数x值)。现在已经尝试了一段时间,但无法弄清楚如何更改x轴标签。也许我需要其他图表类型?

所以问题是如何将x轴上的标签(而不是绘图中xy点旁边的标签)更改为字符串。

for ScenarioIndex := 1 to Mymodel.GetSimulationSetting.GetNumberOfScenarios do
begin
  ScenarioList := Mymodel.GetSimulationSetting.GetScenarioSettingList;
  ScenarioSetting := ScenarioList.Items[ScenarioIndex-1] ;

  //Series1.OnGetMarkText := Series1GetMarkText

  for RunIndex := 1 to Mymodel.GetSimulationSetting.GetNumberOfRuns do
  begin
    for KPIIndex := Low(KPI) to High(KPI) do
    begin
      YValue := ScenarioSetting.GetKPI(RunIndex-1 + KPIIndex * Mymodel.GetSimulationSetting.GetNumberOfRuns);
      XValue := ScenarioIndex;

      if YValue > MaxY then
        MaxY := YValue;
      if YValue < MinY then
        MinY := YValue;
          ScenarioResultChart.Series[KPIIndex].XLabel[1];

      //Add a point to the chart
      ScenarioResultChart.Series[KPIIndex].AddXY(XValue, YValue, inttostr(RunIndex * 100), stringtocolor(KPIinfo[KPIIndex,1]));
      ScenarioResultChart.Series[KPIIndex].Marks.Visible := True;
      ScenarioResultChart.Series[KPIIndex].Marks.Transparent := True;
      ScenarioResultChart.Series[KPIIndex].Marks.Font.Size := 10;
      ScenarioResultChart.Series[KPIIndex].Marks.Arrow.Color := clBlue;
      ScenarioResultChart.Series[KPIIndex].Marks.Arrow.Show;
      //ScenarioResultChart
    end;
  end;
end;

1 个答案:

答案 0 :(得分:1)

要在轴上显示自己的文本而不是X值,请将相应轴的LabelStyle更改为talText并使用OnGetAxisLabel事件:

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
begin
  case ValueIndex of
    0: LabelText := 'first';
    1: LabelText := 'second';
    else
      LabelText := 'smth';
  end;
end;