Dynamic label size for X Axis

Hi. I have a chart with label (labelStyle) text size 15px for my X Axis. The thing is I need to set the size based on conditions. It could be some value I'll get from a rest api or checking the user resolution (like media queries). 

I couldn't find a way to do this in the documentation. Is there a way to actually do this? Like adding an style class to the label so I can actually work with media queries in my style sheet.



Kind regards,
Gabriel

1 Reply 1 reply marked as answer

DG Durga Gopalakrishnan Syncfusion Team August 12, 2020 05:20 PM UTC

Hi Gabriel, 

Greetings from Syncfusion. 

We have analysed your query and suggest you to use axisLabelRender event to customize the axis labels dynamically. We have specified different sizes for axis labels based on the chart width within the axisLabelRender event. Also, we have modified your provided sample and attached the same for your reference. Please check with the below snippet and sample. 

Code Snippet 
 
<ejs-chart #chart (axisLabelRender)="axisLabelRender($event)" > 
</ejs-chart> 
public axisLabelRender(args: IAxisLabelRenderEventArgs): void { 
       if(args.axis.name =="primaryXAxis"){ 
         if(this.chart.availableSize.width <= 200) 
              args.labelStyle.size  = "8px"; 
         //… 
         else 
             args.labelStyle.size  = "20px"; 
       } 
} 

Sample 

UG 

Kindly revert us, if you have any further queries. 

Regards, 
Durga G 


Marked as answer
Loader.
Up arrow icon