Skip to Content

UI5 Gantt chart color based on condition

Hi experts,

How can I set the fill color of a Gantt chart shape based on the value of a property in the bound json model?

Here's the code I am using to configure the sap.gantt.config.Shape :-

var oRectangle = new sap.gantt.config.Shape({
    key: "Rectangle",
    shapeDataName: "schedule",
    shapeClassName: "sap.gantt.shape.Rectangle",
    shapeProperties: {
        time: "{startTime}",
        endTime: "{endTime}",
        height: 32,
        fill: "green",
        title: "{name}",
        level: 0

The use case I am trying to address is :-

If there are 4 or more schedules, then fill the shape with GREEN else fill YELLOW.

I have already tried expression binding like :

fill: "{= ${data>/schedule}.length > 4 ? 'green' : 'yellow' }"

But that didn't give any result and filled the shape with the default BLACK color.

Is there some other way of getting it possible?

Also, is there a way we can configure Gantt shapes in XML views itself ratherer than doing all these configurations the in controller?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Dec 01, 2017 at 09:10 PM


    You are passing "this" to the config function (which the snippet is from) and if not then you have a direct access to the data. So then all you need to do is something along these lines

    var fillColor = "green";
    if (some condition based on the data)
       fillColor = "yellow";
    fill: fillColor,
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.