{"id":8743,"date":"2021-06-15T14:37:27","date_gmt":"2021-06-15T11:37:27","guid":{"rendered":"https:\/\/dhtmlx.com\/blog\/?p=8743"},"modified":"2026-09-15T14:19:59","modified_gmt":"2026-09-15T11:19:59","slug":"custom-content-timeline-javascript-gantt-part-1","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/custom-content-timeline-javascript-gantt-part-1\/","title":{"rendered":"Custom Content in the Timeline of JavaScript Gantt (Part 1)"},"content":{"rendered":"<p>We continue exploring the PRO features of DHTMLX Gantt and sharing with you some curious details that can be helpful in project management applications.<\/p>\n<p>Our <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxGantt\/\" rel=\"noopener\" target=\"_blank\">HTML5 Gantt chart<\/a> component is loved for its enhanced customization capabilities. A basic Gantt chart timeline commonly includes tasks and dependency links between them. But an extensive API of our component helps to make the Gantt chart more informative for end-users by complementing its timeline area with custom HTML content. <\/p>\n<p>In this post, we will review vivid examples of how to create custom baselines, highlight overdue tasks, and display task progress value in the Gantt timeline.<\/p>\n<h2>Use cases of custom content in Gantt timeline<\/h2>\n<p>When it comes to integrating custom items in Gantt charts built with DHTMLX, it is necessary to create a layer and then embed the required content in it. Our Gantt component offers the <strong><a href=\"https:\/\/docs.dhtmlx.com\/gantt\/api__gantt_addtasklayer.html\" rel=\"noopener\" target=\"_blank\">addTaskLayer<\/a><\/strong> method for displaying custom elements such as baselines or deadlines in the timeline area. Moreover, there is the <strong>overlay<\/strong> extension that can be used with any third-party library for generating custom content on top of the Gantt chart. More technical details on utilizing both these approaches can be found <a href=\"https:\/\/docs.dhtmlx.com\/gantt\/desktop__baselines.html#extraoverlayforthechart\" rel=\"noopener\" target=\"_blank\">in the documentation<\/a>. But we will focus on examples implemented with the <strong>addTaskLayer<\/strong> method.<\/p>\n<h3>Custom baselines<\/h3>\n<p>The need to display custom baselines (or deadlines) is one of the most common examples of using extra layers with DHTMLX Gantt. The image below shows good-looking custom baselines added in the Gantt timeline.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image1-1024x450.png\" alt=\"custom baselines in DHTMLX Gantt\" width=\"1024\" height=\"450\" class=\"aligncenter size-large wp-image-8745\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image1-1024x450.png 1024w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image1-300x132.png 300w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image1-768x337.png 768w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image1.png 1273w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><em><a href=\"https:\/\/snippet.dhtmlx.com\/5\/94dd464a0\" rel=\"noopener\" target=\"_blank\">Check the sample ><\/a><\/em><\/p>\n<p>In this example, baselines are positioned vertically as well as tasks. By default, elements of the extra layer will be placed behind tasks (it can be changed with styles, but in our example, it is not necessary). <\/p>\n<p>You have to use the <strong>getTaskPosition<\/strong> method to obtain the coordinates where custom items (baselines) should be drawn. Here you need to specify the <strong>task<\/strong> object and 2 dates (start and end dates of the baseline element). The appearance of baselines and coordinates are defined using styles.<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">gantt.<span class=\"me1\">addTaskLayer<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw1\">function<\/span> draw_planned<span class=\"br0\">&#40;<\/span>task<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>task.<span class=\"me1\">planned_start<\/span> <span class=\"sy0\">&amp;&amp;<\/span> task.<span class=\"me1\">planned_end<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">var<\/span> sizes <span class=\"sy0\">=<\/span> gantt.<span class=\"me1\">getTaskPosition<\/span><span class=\"br0\">&#40;<\/span>task<span class=\"sy0\">,<\/span> task.<span class=\"me1\">planned_start<\/span><span class=\"sy0\">,<\/span> task.<span class=\"me1\">planned_end<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">var<\/span> el <span class=\"sy0\">=<\/span> document.<span class=\"me1\">createElement<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'div'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; el.<span class=\"me1\">className<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">'baseline'<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; el.<span class=\"me1\">style<\/span>.<span class=\"me1\">left<\/span> <span class=\"sy0\">=<\/span> sizes.<span class=\"me1\">left<\/span> <span class=\"sy0\">-<\/span> <span class=\"nu0\">6<\/span> <span class=\"sy0\">+<\/span> <span class=\"st0\">'px'<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; el.<span class=\"me1\">style<\/span>.<span class=\"me1\">width<\/span> <span class=\"sy0\">=<\/span> sizes.<span class=\"me1\">width<\/span> <span class=\"sy0\">+<\/span> <span class=\"nu0\">10<\/span> <span class=\"sy0\">+<\/span> <span class=\"st0\">'px'<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; el.<span class=\"me1\">style<\/span>.<span class=\"me1\">height<\/span> <span class=\"sy0\">=<\/span> sizes.<span class=\"me1\">height<\/span> <span class=\"sy0\">+<\/span> <span class=\"nu0\">6<\/span> <span class=\"sy0\">+<\/span> <span class=\"st0\">'px'<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; el.<span class=\"me1\">style<\/span>.<span class=\"me1\">top<\/span> <span class=\"sy0\">=<\/span> sizes.<span class=\"me1\">top<\/span> <span class=\"sy0\">+<\/span> <span class=\"nu0\">1<\/span> <span class=\"sy0\">+<\/span> <span class=\"st0\">'px'<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> el<span class=\"sy0\">;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw2\">false<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"sy0\">&lt;<\/span>style<span class=\"sy0\">&gt;<\/span><br \/>\n&nbsp; .<span class=\"me1\">baseline<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; position<span class=\"sy0\">:<\/span> absolute<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; border<span class=\"sy0\">-<\/span>radius<span class=\"sy0\">:<\/span> 2px<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; z<span class=\"sy0\">-<\/span>index<span class=\"sy0\">:<\/span><span class=\"nu0\">0<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; opacity<span class=\"sy0\">:<\/span> <span class=\"nu0\">0.3<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; background<span class=\"sy0\">:<\/span> #6dadf0<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; border<span class=\"sy0\">:<\/span> 1px solid #4a6bf8<span class=\"sy0\">;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; .<span class=\"me1\">gantt_task_line<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; .<span class=\"me1\">baseline<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; border<span class=\"sy0\">-<\/span>radius<span class=\"sy0\">:<\/span>20px<span class=\"sy0\">;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"sy0\">&lt;\/<\/span>style<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>That\u2019s how you can generate custom baselines using the <strong>getTaskPosition<\/strong> method and add them to the Gantt timeline.<\/p>\n<h3>Highlighting overdue tasks<\/h3>\n<p>In real projects, tasks are frequently rescheduled causing time lags relative to the initial baselines and deadlines. End-users should be informed about such issues. For this purpose, you can come up with different custom solutions.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image7.png\" alt=\"Highlighting tasks with ovedue status\" width=\"955\" height=\"158\" class=\"aligncenter size-full wp-image-8749\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image7.png 955w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image7-300x50.png 300w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image7-768x127.png 768w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><a href=\"https:\/\/snippet.dhtmlx.com\/5\/fad73bd9d\" rel=\"noopener\" target=\"_blank\">Check the sample ><\/a><\/p>\n<p>For instance, you can highlight cells in the timeline where the task duration exceeds the related baseline\/deadline. In the presented example, the baseline is drawn in a simpler way (compared to other examples reviewed in this article) and cells are highlighted with the help of the <strong>task_cell_class<\/strong> template:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">gantt.<span class=\"me1\">templates<\/span>.<span class=\"me1\">task_cell_class<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw1\">function<\/span><span class=\"br0\">&#40;<\/span>item<span class=\"sy0\">,<\/span>date<span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>item.<span class=\"me1\">planned_end<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>item.<span class=\"me1\">end_date<\/span> <span class=\"sy0\">&gt;=<\/span> item.<span class=\"me1\">planned_end<\/span> <span class=\"sy0\">&amp;&amp;<\/span> date <span class=\"sy0\">&gt;=<\/span> item.<span class=\"me1\">planned_end<\/span> <span class=\"sy0\">&amp;&amp;<\/span> date <span class=\"sy0\">&lt;<\/span> item.<span class=\"me1\">end_date<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> <span class=\"st0\">&quot;overdue_cell&quot;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>The template will be called for each timeline cell (and for each task row). First, make sure that the task for the timeline row has the deadline date. Then check two conditions:<\/p>\n<ul>\n<li>the task ends later than it was planned (the task&#8217;s end date is greater than the deadline date)<\/li>\n<li>the cell starts after the deadline but before the task ends (the cell&#8217;s date is greater than the deadline date and lower than the task&#8217;s end_date)<\/li>\n<\/ul>\n<p>In addition, you can also make use of the <strong>rightside_text<\/strong> template and apply the same approach in it. If the task end date exceeds the deadline, estimate how many days it exceeds the planned end date and return this value with the text `Overdue`:<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">gantt.<span class=\"me1\">templates<\/span>.<span class=\"me1\">rightside_text<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw1\">function<\/span> <span class=\"br0\">&#40;<\/span>start<span class=\"sy0\">,<\/span> end<span class=\"sy0\">,<\/span> task<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>task.<span class=\"me1\">planned_end<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>end.<span class=\"me1\">getTime<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> task.<span class=\"me1\">planned_end<\/span>.<span class=\"me1\">getTime<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"kw1\">var<\/span> overdue <span class=\"sy0\">=<\/span> <span class=\"kw4\">Math<\/span>.<span class=\"me1\">ceil<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw4\">Math<\/span>.<span class=\"me1\">abs<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#40;<\/span>end.<span class=\"me1\">getTime<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">-<\/span> task.<span class=\"me1\">planned_end<\/span>.<span class=\"me1\">getTime<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">\/<\/span> <span class=\"br0\">&#40;<\/span><span class=\"nu0\">24<\/span> <span class=\"sy0\">*<\/span> <span class=\"nu0\">60<\/span> <span class=\"sy0\">*<\/span> <span class=\"nu0\">60<\/span> <span class=\"sy0\">*<\/span> <span class=\"nu0\">1000<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"kw1\">var<\/span> text <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;&lt;b&gt;Overdue: &quot;<\/span> <span class=\"sy0\">+<\/span> overdue <span class=\"sy0\">+<\/span> <span class=\"st0\">&quot; days&lt;\/b&gt;&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; <span class=\"kw1\">return<\/span> text<span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>It is also possible to change the color of tasks with an overdue status. You can check the dates of tasks in the <strong>task_class<\/strong> template and return the class name for tasks that are completed later than planned. The appearance of such tasks is fully customizable via styles.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image3-1024x152.png\" alt=\"Highlighting tasks with overdue tasks\" width=\"1024\" height=\"152\" class=\"aligncenter size-large wp-image-8751\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image3-1024x152.png 1024w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image3-300x45.png 300w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image3-768x114.png 768w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image3.png 1058w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><a href=\"https:\/\/snippet.dhtmlx.com\/5\/e395c26c3\" rel=\"noopener\" target=\"_blank\">Check the sample ><\/a><\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">gantt.<span class=\"me1\">templates<\/span>.<span class=\"me1\">task_class<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw1\">function<\/span> <span class=\"br0\">&#40;<\/span>start<span class=\"sy0\">,<\/span> end<span class=\"sy0\">,<\/span> task<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>task.<span class=\"me1\">planned_end<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">var<\/span> classes <span class=\"sy0\">=<\/span> <span class=\"br0\">&#91;<\/span><span class=\"st0\">'has-baseline'<\/span><span class=\"br0\">&#93;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>end.<span class=\"me1\">getTime<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">&gt;<\/span> task.<span class=\"me1\">planned_end<\/span>.<span class=\"me1\">getTime<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; classes.<span class=\"me1\">push<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'overdue'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw1\">return<\/span> classes.<span class=\"me1\">join<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">' '<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>In previous examples, we have worked with deadlines for individual tasks. But what about showing the missed deadline for the whole project? To that end, we utilize the <strong>Marker <\/strong> extension to display a deadline.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image9.png\" alt=\"Gantt timeline with the broken project deadline\" width=\"999\" height=\"248\" class=\"aligncenter size-full wp-image-8752\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image9.png 999w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image9-300x74.png 300w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/image9-768x191.png 768w\" sizes=\"auto, (max-width: 999px) 100vw, 999px\" \/><em><a href=\"https:\/\/snippet.dhtmlx.com\/5\/7abb89fe8\" rel=\"noopener\" target=\"_blank\">Check the sample ><\/a><\/em><\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">gantt.<span class=\"me1\">plugins<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; marker<span class=\"sy0\">:<\/span> <span class=\"kw2\">true<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"kw1\">var<\/span> deadline <span class=\"sy0\">=<\/span> <span class=\"kw1\">new<\/span> <span class=\"kw4\">Date<\/span><span class=\"br0\">&#40;<\/span><span class=\"nu0\">2025<\/span><span class=\"sy0\">,<\/span>03<span class=\"sy0\">,<\/span>03<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"kw1\">var<\/span> todayMarker <span class=\"sy0\">=<\/span> gantt.<span class=\"me1\">addMarker<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#123;<\/span> <br \/>\n&nbsp; start_date<span class=\"sy0\">:<\/span> deadline<span class=\"sy0\">,<\/span> <br \/>\n&nbsp; css<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;today&quot;<\/span><span class=\"sy0\">,<\/span> <br \/>\n&nbsp; text<span class=\"sy0\">:<\/span> <span class=\"st0\">&quot;Deadline&quot;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>The logic for elements in the extra layer is the following. First of all, it is necessary to check if the task duration exceeds the deadline. If so, you have to set the deadline date for the left date (start date) of the extra layer element. But our goal here is to highlight the whole task if it exceeds the deadline date, rather than the area from the deadline to the end date of the task. If the task starts before the deadline and ends after it, we highlight the part of the task. If the task starts after the deadline, the whole task should be highlighted. Therefore, if the start date of the task is greater than the deadline, then the start date of the task becomes the left date of the deadline element. The right date (end-date) of the deadline element will be the end date of the task. Coordinates for the deadline element are obtained via the <strong>getTaskPosition<\/strong> method. After that styles are added.<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\"><span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><span class=\"sy0\">+<\/span>task.<span class=\"me1\">start_date<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">+<\/span>deadline <span class=\"sy0\">||<\/span> <span class=\"sy0\">+<\/span>task.<span class=\"me1\">end_date<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">+<\/span>deadline<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; <span class=\"kw1\">var<\/span> start_date <span class=\"sy0\">=<\/span> deadline<span class=\"sy0\">;<\/span><br \/>\n&nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><span class=\"sy0\">+<\/span>task.<span class=\"me1\">start_date<\/span> <span class=\"sy0\">&gt;<\/span> <span class=\"sy0\">+<\/span>deadline<span class=\"br0\">&#41;<\/span> start_date <span class=\"sy0\">=<\/span> task.<span class=\"me1\">start_date<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp; <span class=\"kw1\">var<\/span> sizes <span class=\"sy0\">=<\/span> gantt.<span class=\"me1\">getTaskPosition<\/span><span class=\"br0\">&#40;<\/span>task<span class=\"sy0\">,<\/span> start_date<span class=\"sy0\">,<\/span> task.<span class=\"me1\">end_date<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>In this example, we have reviewed several helpful ways of highlighting tasks that do not meet time constraints specified in baselines and deadlines.<\/p>\n<h3>Task progress value<\/h3>\n<p>It can also be useful for end-users to be able to see the progress value of any project task and change it on the fly.<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2021\/06\/Gantt-Task-Value.gif\" alt=\"Task progress value in the timeline\" width=\"771\" height=\"251\" class=\"aligncenter size-full wp-image-8835\" \/><em><a href=\"https:\/\/snippet.dhtmlx.com\/5\/e9a4bcbb9\" rel=\"noopener\" target=\"_blank\">Check the sample ><\/a><\/em><\/p>\n<p>By default, the progress value of tasks is not displayed in the Gantt chart. It is possible to display it in the grid by adding a custom column. But it can be inconvenient for users to follow this parameter in the grid when visual changes take place in the timeline. Thus, it is more reasonable to apply an additional layer for depicting the progress value in the timeline. Using the <strong>getTaskPosition<\/strong> method get the coordinates of the task and then add a margin for the <strong>left<\/strong> parameter. In the styles add the <strong>z-index<\/strong> parameter to display a custom progress element on top of a given task.<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\"><span class=\"kw1\">var<\/span> sizes <span class=\"sy0\">=<\/span> gantt.<span class=\"me1\">getTaskPosition<\/span><span class=\"br0\">&#40;<\/span>task<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw1\">var<\/span> el <span class=\"sy0\">=<\/span> document.<span class=\"me1\">createElement<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'div'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\nel.<span class=\"me1\">className<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">'progress_value'<\/span><span class=\"sy0\">;<\/span><br \/>\nel.<span class=\"me1\">innerHTML<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw4\">Math<\/span>.<span class=\"me1\">round<\/span><span class=\"br0\">&#40;<\/span>task.<span class=\"me1\">progress<\/span> <span class=\"sy0\">*<\/span><span class=\"nu0\">100<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">+<\/span><span class=\"st0\">&quot;%&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\nel.<span class=\"me1\">style<\/span>.<span class=\"me1\">left<\/span> <span class=\"sy0\">=<\/span> sizes.<span class=\"me1\">left<\/span> <span class=\"sy0\">+<\/span> <span class=\"br0\">&#40;<\/span>sizes.<span class=\"me1\">width<\/span> <span class=\"sy0\">\/<\/span> <span class=\"nu0\">3<\/span><span class=\"br0\">&#41;<\/span> <span class=\"sy0\">+<\/span> <span class=\"st0\">'px'<\/span><span class=\"sy0\">;<\/span><br \/>\nel.<span class=\"me1\">style<\/span>.<span class=\"me1\">top<\/span> <span class=\"sy0\">=<\/span> sizes.<span class=\"me1\">top<\/span> <span class=\"sy0\">+<\/span> <span class=\"st0\">'px'<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"kw1\">return<\/span> el<span class=\"sy0\">;<\/span><\/div><\/div>\n<p>If you want the element to be displayed only for the task with changing progress, you first need to get an ID for this task with the help of <strong>gantt.getState().drag_id<\/strong> and compare IDs of the tasks when creating an extra layer.<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\">gantt.<span class=\"me1\">addTaskLayer<\/span><span class=\"br0\">&#40;<\/span><span class=\"kw1\">function<\/span> <span class=\"br0\">&#40;<\/span>task<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; <span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span>gantt.<span class=\"me1\">getState<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>.<span class=\"me1\">drag_id<\/span> <span class=\"sy0\">==<\/span> task.<span class=\"me1\">id<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp;<span class=\"sy0\">&lt;<\/span>..<span class=\"sy0\">&gt;<\/span><br \/>\n&nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n&nbsp; <span class=\"kw1\">return<\/span> <span class=\"kw2\">false<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p>By following these instructions, you can visualize the progress values of project tasks and edit this parameter in real-time.<\/p>\n<h3>Conclusion<\/h5>\n<p>Summarizing the above, we can say that DHTMLX Gantt provides plenty of options for using custom HTML content in the Gantt timeline. Multiple interactive examples reviewed in this article show how you can benefit from the full customizability of our Gantt library in real-case scenarios. <\/p>\n<p>Want to test the gained knowledge in your own project? Just download a <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxGantt\/download.shtml\" rel=\"noopener\" target=\"_blank\">free 30-day evaluation version<\/a> of our JavaScript Gantt component and get down to it.<\/p>\n<p>Next time we will share with you more complex examples on utilizing custom content in DHTMLX-based Gantt charts that will require extra code modifications. Stay tuned.<\/p>\n<h5>Related materials:<\/h5>\n<ul>\n<li><a href=\"https:\/\/docs.dhtmlx.com\/gantt\/\" rel=\"noopener\" target=\"_blank\">DHTMLX Gantt Documentation<\/a><\/li>\n<li><a href=\"https:\/\/docs.dhtmlx.com\/gantt\/demos\/\" rel=\"noopener\" target=\"_blank\">DHTMLX Gantt Samples<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>We continue exploring the PRO features of DHTMLX Gantt and sharing with you some curious details that can be helpful in project management applications. Our HTML5 Gantt chart component &#8230;<\/p>\n","protected":false},"author":101014,"featured_media":8851,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[71],"tags":[33,20],"class_list":["post-8743","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-all-posts","tag-gantt"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/8743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/101014"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=8743"}],"version-history":[{"count":27,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/8743\/revisions"}],"predecessor-version":[{"id":15885,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/8743\/revisions\/15885"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/8851"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=8743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=8743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=8743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}