Search code examples
delphiplotlabelteechart

change x-axis label in xy value plot


I'm trying to change the labels on xyplot in Delphi. Next to showing a label next to the datapoint, the x-axis needs a label as well (currently it shows the integer x value). Trying for some time already now but can't figure out how to change x-axis label. Maybe I need another chart type?

So questions is how can I change labels on x-axis (not the ones next to xy point in plot) to strings.

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;

Solution

  • To show own text instead of X-value on axis, change LabelStyle for corresponding axis to talText and use OnGetAxisLabel event:

    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;