javascriptreactjsapexchartspersian-calendar

Displaying Persian/Jalali dates in react apexchart


Could you guide me on how to make a "Datetime X-Axis" chart with react Apexchart.js when my dates are in Persian? at last, I should make a "brushChart" with Datetime X-Axis, if you have a similar project that can help me please send link of them

I had these codes below and I tried "defaultLocale" and "name" with both "Per" and "Fa" but none of them worked and getting a error and the app crashed.

chart: {
  id: 'reactchart-example',
  defaultLocale: 'Fa',
  locales: [
    {
      name: 'per',
      options: {
        months: [
          'دی',
          'بهمن',
          'اسفند',
          'فروردین',
          'اردیبهشت',
          'خرداد',
          'تیر',
          'مرداد',
          'شهریور',
          'مهر',
          'آبان',
          'آذر',
        ],
        shortMonths: ['دی', 'بهم', 'اسف', 'فرو', 'ارد', 'خرد', 'تیر', 'مرد', 'شهر', 'مهر', 'آبا', 'آذر'],
        days: ['یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنج شنبه', 'جمعه', 'شنبه'],
        shortDays: ['یک', 'دو', 'سه', 'چهار', 'پنج', 'جمع', 'شنب'],
        toolbar: {
          download: 'دانلود SVG',
          selection: 'انتخاب',
          selectionZoom: 'انتخاب بزرگنمایی',
          zoomIn: 'بزرگنمایی',
          zoomOut: 'کوچک نمایی',
          pan: 'جابجایی',
          reset: 'بازگرداندن',
        },
      },
    },
  ],
},

thanks for your help


Solution

  • you don't need to add the whole config in your chart object, there is a json file for every locale in this address in your node_modules folder: "apexcharts/dist/locales/"

    all you need is to import your desired locale json file in your code like below

    import fa from "apexcharts/dist/locales/fa.json"
    

    and then simply set "locales" array and "defaultLocale" in the object "chart" like below:

    chart: {
      //The following two lines are the key answer
      locales: [fa], //or multi language like [fa, en]
      defaultLocale: 'fa',
      
      //your other configs ...
    },