如何在Chartjs中为Yaxis实现RTL

qyswt5oh  于 2024-01-07  发布在  Chart.js
关注(0)|答案(2)|浏览(255)

目前,我在一个网站上工作,我必须对齐标签和工具提示,因为它的阿拉伯文文本RTL。
我已经阅读了文档和搜索了很多,但无法理解为什么RTL不为工具提示和标签工作
检查屏幕截图:标签:https://prnt.sc/q95lf8工具提示:https://prnt.sc/q95mbz
下面是我的代码:

  1. config.options.scales.xAxes =[ {
  2. display: true,
  3. scaleLabel: {
  4. display: true,
  5. labelString: utils.getTranslations('average_complaints_for_1000', 'statistics'),
  6. fontStyle: 'bold',
  7. fontSize: (window.innerWidth<400)? 13 : 20,
  8. align : 'right',
  9. },
  10. }];
  11. config.options.scales.yAxes[0].display=true;
  12. config.options.scales.yAxes[0].ticks={
  13. fontSize: (window.innerWidth<400)? 13 :14 ,
  14. fontFamily:'DroidKufi-Regular',
  15. };
  16. config.options.tooltips.enabled = true;
  17. this.generate_chart({
  18. container: '#bank_rate_of_complaints--section-1',
  19. canvas_id: 'bank_rate_of_complaints_canvas_1',
  20. chart_config: config,
  21. canvas_height: (data_set.labels.length < 6)? 70 : (data_set.labels > 5 && data_set.labels.length< 10 )? 190 : 300
  22. });

字符串

64jmpszr

64jmpszr1#

您可以在工具提示中使用rtl和其他设置,如下所示:

  1. options = {
  2. tooltips: {
  3. rtl: true,
  4. bodyFontSize: 10,
  5. titleFontSize: 11,
  6. }}

字符串
我已经用它为波斯图表和工作正确。

ep6jt1vc

ep6jt1vc2#

您可以使用y轴的位置选项来执行此操作:

  1. let isRightToLeft = true;
  2. chart.options = {
  3. scales: {
  4. y: {
  5. position: isRightToLeft ? 'right' : 'left',
  6. }
  7. }
  8. };

字符串

相关问题