Search code examples
.netxamarin.iosteechart

Change color of a label in the barChart (TeeChart)


I have a simpele bar chart with 4 labels. I want the 3rd label to be WHITE and have a BOLD interface.

I tried to access the Axis.Labels.Items and manipulate these, but the collection seems to be containing no elements. The event GetAxisDrawElement gives me the label but I have no access on the font and color properties.


Solution

  • You can use the GetAxisLabel event, e.g.

    private void InitializeChart()
    {
      Bar series = new Bar(tChart1.Chart);
      series.Add(1);
      series.Add(2);
      series.Add(3);
      series.Add(4);
    
      tChart1.GetAxisLabel += tChart1_GetAxisLabel;
    }
    
    void tChart1_GetAxisLabel(object sender, GetAxisLabelEventArgs e)
    {
      Axis axis = sender as Axis;
    
      if(axis.Equals(tChart1.Axes.Bottom))
      {
        axis.Labels.Font.Bold = e.LabelText.Equals("3");
        axis.Labels.Font.Color = e.LabelText.Equals("3") ? Color.Red : Color.Black;
        axis.Labels.Font.Size = e.LabelText.Equals("3") ? 16 : 8;
      }
    }