Jump to content
We've recently updated our Privacy Statement, available here ×
  • Dynamically Updating bar colors in HTML5 Bar Charts


    emistry
    • Features: Charts Version: v5.6 Product: JasperReports® Server

    HTML5BarChart-CustomiseColors(1).zip

    This example guides a developer through creating a bar chart that changes bar colors depending on a threshold and also based on the current month. The final product will look like this:

    test.png.8fd79f97493ccb0979f12b75c8aafede.png

    (Red is Current Month, Blue is Sales if Over 50000, Green is if they are under)

    (JRXML file attached)

    1. This example uses the Foodmart database that is included with the Jaspersoft BI Suite if you choose to install samples. Create a simple report with the following query :

      SELECT sum(sales_fact_1997.store_sales) as sales,
             time_by_day.the_month
        FROM sales_fact_1997
             INNER JOIN time_by_day ON
                        time_by_day.time_id = sales_fact_1997.time_id
               GROUP BY the_month, month_of_year
               ORDER BY month_of_year
      
    2. Add a HTML5 – Column Chart to the summary band and delete all the other bands

    3. Goto the HTML5 Charts Properties -> Chart Data -> Configuration page

      1(61).png.de4768adbb3ff665ffa804483206076e.png

    4. Modify the “Categories Level” to remove the default “Level1” category and Add the Month category as below …

      2(53).png.3ccb4f3349b7a28cf0f2e77daba28acb.png

    5. Add the Bucket Property : color

      3(34).png.43371e11aebbd83a25af25fd28d46017.png

      The Magic …this

      With this as the property expression:

      IF($F{the_month}.toString().matches(DATEFORMAT(new Date(),"MMMMM")),"red",IF($F{sales}.intValue() >= 50000,"green","blue"))

      and the Bucket property page should look like this :

      4(31).png.49e8a438502732f5e0a3ea5d2cae5176.png

    6. Return to the Chart Properties page

      5(27).png.4594e0a4263c85e93e17a7d47ab097d2.png

    7. Remove the default measure and Add the following Value Definition

      6(20).png.b8b6c25eef5e27d5b3520b8e012a0453.png

    8. And the following Advanced property:

      7(15).png.4a9a18653d91cfa9c33aefdd64f33652.png

    9. Return back to the report view and preview the Report:

      test(1).png.ff3ff9497d630a8dce40fd84cc087ad1.png


    User Feedback

    Recommended Comments



    Guest
    This is now closed for further comments

×
×
  • Create New...