Search code examples
c#chartslabeldevexpresstextpattern

Quarter Textpattern for a label in devexpress chart


I want to display quarter format for a label on xaxis in devexpress chart. To do this,there's a property called TextPattern as following,

diagram.AxisX.Label.TextPattern = "{A:q}" ;

result would be : Q2-2016

But i want substring of above result, i.e. Q2

How can i get that?


Solution

  • you can do a trick to display only the first 2 characters, like this :

    diagram.AxisX.Label.TextPattern = "{A:q}";
    diagram.AxisX.Label.MaxLineCount = 1;
    diagram.AxisX.Label.MaxWidth = 20;
    

    You can change MaxWidth value depending on the size of your Label

    Or you can use CustomDrawAxisLabel event of ChartControl like this:

    private void chartControl1_CustomDrawAxisLabel(object sender, CustomDrawAxisLabelEventArgs e)
    {
        AxisBase axis = e.Item.Axis;
        if (axis is AxisX)
        {
           e.Item.Text =  e.Item.Text.Substring(0,2) ;
        }
    }