Converting Dates to Days on X Axis in a Chart

  • Last update:March 17, 2025
  • Overview

    Problem

    When the date field is used as a category, the category name on the X axis can only be a specific date. How can you convert these dates into days? The following figure shows the effect.

    image 37.png

    Implementation Method

    Two methods are available for converting dates to days:

    Method one:  You can directly use the weekday() function in the SQL statement to convert the date.

    Method two: When designing the report, set the data dictionary for the chart category. In the data dictionary, use the built-in switch() and weekday() functions to convert the displayed value of the date to weekday.

    iconNote:
    This document only demonstrates method two. You can modify the SQL statement to perform method one by yourself.

    Example

    Data Preparation

    1. Create a built-in dataset with two column fields: Date (date type) and Amount (string type), as shown in the following figure.

    image 39.png

    2. Enter ten records of data in the two columns, as shown in the following figure.

    image 38.png

    Chart Insertion

    Merge  required cells, insert a column chart, and bind the data to the column chart. The following figure shows the detalied setting.

    image 40.png

    Data Filter Setting

    To display the data of a week, set Data Filter to only extract the first seven records of the data, as shown in the following figure.

    image 41.png

    Data Dictionary Setting

    Set Display to Data Dictionaryunder Data Filter > Category. Set Type of Data Dictionary to Formula, and the formula corresponding to Actual Value and Display Value is as follows:

    • Actual value: $$$

    • Display value: switch(weekday($$$),0,"Sunday",1,"Monday",2,"Tuesday",3,"Wednesday",4,"Thursday",5,"Friday",6,"Saturday")

    image 45.png

    Effect Display

    1. PC

    Save the report and click Pagination Preview. The following figure shows the preview effect.

    image 37.png

    2. Mobile Terminal

    The report can be previewed on the DataAnalyst APP and theH5 terminal, as shown in the following figure.

    微信图片_20250317000006.jpg

    Template Download

    Click to download the template Converting Dates to Days on X Axis in a Chart.cpt.

    Attachment List


    Theme: Chart
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    9s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy