1

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;
  • So you want to mke labels with exact x-values on axis instead of equidistant grid values? – MBo Aug 12 '19 at 09:03
  • Hi MBo, thanks for taking the time to answer the question... No, where it shows 1 (value) on the x-axis now it should show for example "Scenario 1: Baseline" instead and where it shows 2 it should show "Scenario extra LT" for example. We add points only on x=1 , x=2 , x=3, etc... – bram van luijtelaar Aug 12 '19 at 09:41
  • OK, I changed my answer – MBo Aug 12 '19 at 10:03
  • That looks good :) Will try to implement and let you know.... Thanks! – bram van luijtelaar Aug 12 '19 at 10:49

1 Answers1

1

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;
MBo
  • 77,366
  • 5
  • 53
  • 86