JS Realizing to Change The Color Of The Specified Category Name

  • Last update:December 29, 2021
  • I. Overview

    1. Problem description

    When displaying charts, sometimes in order to highlight the impact of certain categories on the value, a special display of the category name is required.

    For example, in the sales volume of one month, marking the category names of two weekends in red, the effect is shown in the following figure:

    1.png


    2. Implementation ideas

    Use JS to customize the label format of the category axis.

    II. Example

    1. Report design

    1) Create a New General Report, and create a new built-in datasetEmbedded1, as shown in the figure below:

    2.png

    2) Insert a line chart into the cell, and bind the chart data as shown below:

    3.png

    3) Select the line chart, customize the axis label format in Style>Axis>X Axis, and Use HTML parsing text content, as shown in the following figure:

    4.png

    The JS code is as follows:

    function()
        var date = new Date(this);
        if(date.getDay()==0||date.getDay()==6){
            return "<font color='red'>"+date.getDate()+"</font>"
        }else{
            return date.getDate();
        }
    }


    2. Effect preview

    1) PC 

    Save the report, click the Pagination Preview, the effect is as shown in the figure below:

    5.png

    2) Mobile

    6.png

    III. Template download

    The completed template can be found in:%FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\JS\Chart JS Example\JS Realizing to Change The Color Of The Specified Category Name.cpt

    Click to download the template: 

    JS Realizing to Change The Color Of The Specified Category Name.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