Bar chart but in gantt (24h) style?

Hey Guys,

We try to move our time reports from an older framework to syncfusion.

But i cant find anything that matches our needs, maybe i just dont found the chart...
You guys have something like that:


Is it possible to crate this diagram throug a normal bar chart like the one below?


Ty for your help :)
Kindly regards
Dominic

13 Replies

BP Baby Palanidurai Syncfusion Team April 9, 2020 09:18 AM UTC

Hi Dominic, 
 
Greetings from Syncfusion. 
 
We have analyzed your query. We have prepared a sample based on your requirement.  Please find the below screenshot and sample, 
 
 
Screenshot: 
 
 
 
 
Kindly revert us, if you have any concerns. 
 
Regards, 
Baby. 



DB Dominic Buerki April 9, 2020 12:13 PM UTC

Thank you very much for this example, its verry similar to what i'm looking for, i think i can work with this!

Kindly Regards
Dominic




BP Baby Palanidurai Syncfusion Team April 10, 2020 05:46 AM UTC

Hi Dominic, 

Most welcome. Please revert us, if you have any other concerns. 

Regards, 
Baby. 



DB Dominic Buerki April 14, 2020 01:59 PM UTC

Hey Baby,

There is something more i have to know.

You have defined a specific amount of "StackingItems" in the UI and then in the Class behind.
But is it possible to define a variable amount of those Items?
Because we have a different amount of Activities to draw for each day.

Thank you, Dominic



DG Durga Gopalakrishnan Syncfusion Team April 16, 2020 03:45 AM UTC

Hi Dominic, 

We are validating your reported scenario. We will update the status within one business day(16th April, 2020). We appreciate your patience until then. 

Regards, 
Durga G 



DB Dominic Buerki April 16, 2020 04:52 AM UTC

Hey,

Thank you very much.
As an Example i can show you a list of my class which should be printed:

List<ChartData> chartData = new List<ChartData>
            {
                new ChartData { StartTime = new DateTime(2019, 8, 19, 0, 0, 0), EndTime = new DateTime(2019, 8, 19, 1, 0, 0), Type = "Green" },
                new ChartData { StartTime = new DateTime(2019, 8, 19, 1, 0, 0), EndTime = new DateTime(2019, 8, 19, 1, 30, 0), Type = "Red" },
                new ChartData { StartTime = new DateTime(2019, 8, 19, 1, 30, 0), EndTime = new DateTime(2019, 8, 19, 2, 0, 0), Type = "Blue" },
                new ChartData { StartTime = new DateTime(2019, 8, 19, 2, 0, 0), EndTime = new DateTime(2019, 8, 19, 3, 0, 0), Type = "Red" },
            };

Kindly regards
Dominic


DG Durga Gopalakrishnan Syncfusion Team April 16, 2020 01:20 PM UTC

Hi Dominic, 

We have analysed your query. We suggest you to bind the series for chart in code behind as a collection for provided data source. We have prepared sample for your reference. Please check with the below code snippet and sample. 

Code Snippet 

Index.cshtml 
 
<ejs-chart id="myContainer" series="@ViewBag.seriesCollection"> 
</ejs-chart> 
 
HomeController.cs 
 
public IActionResult Index() 
{ 
   List<ChartSeries> collection = new List<ChartSeries>(); 
   List<StackedBar100ChartData> chartData = new List<StackedBar100ChartData> 
   { 
      new StackedBar100ChartData { x= "19.8.2019", y0= 1.1, y1=0.4, y2=0.6, y3=0.8, y4=0.1, y5=12 } 
      //…              
   }; 
   string[] colors = new string[] { "lime","red","blue","red","blue","lime"}; 
   for(int i =0;i<6; i++) 
   { 
       ChartSeries series = new ChartSeries(); 
       series.XName = "x"; 
       series.YName = "y"+i; 
       series.DataSource = chartData; 
       series.Fill = colors[i]; 
       series.Type = Syncfusion.EJ2.Charts.ChartSeriesType.StackingBar100; 
       collection.Add(series); 
   } 
   ViewBag.seriesCollection = collection; 
   return View(); 
} 

Sample 

Kindly revert us, if you have any concerns. 

Regards, 
Durga G


DB Dominic Buerki April 17, 2020 05:39 AM UTC

Thank you for your example.

 

Unfortunately this won't help me to solve my problem, or I don't understand how to map my data to your way of creating the chart.

 

Let me go back to my original question.

 

The goal is to display time durations for given days.

So I need some kind of chart/table that has a date on one axis and a time duration on the other axis. The time durations are of a certain type, which should be presented in different colors.

 

If you look at the picture in the original post, then my data for the first row would look like this:

 

public class ChartData

{

    public string Date { get; set; }

    //note: these could be minutes, hours, timespans or datetimes, whatever is easiest

    public double StartTime { get; set; }

    public double EndTime { get; set; }

    public string Type { get; set; }

}

 

List<ChartData> chartData = new List<ChartData>

{

                new ChartData { Date = "19.08.2019", StartTime = 0, EndTime = 1, Type = "Green" },

                new ChartData { Date = "19.08.2019", StartTime = 1, EndTime = 1.5, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 1.5, EndTime = 2, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 2, EndTime = 2.75, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 2.75, EndTime = 2.9, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 2.9, EndTime = 3.1, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 3.1, EndTime = 3.2, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 3.2, EndTime = 3.3, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 3.3, EndTime = 3.4, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 3.4, EndTime = 4, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 4, EndTime = 4.2, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 4.2, EndTime = 4.3, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 4.3, EndTime = 4.5, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 4.5, EndTime = 4.9, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 4.9, EndTime = 5, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 5, EndTime = 5.2, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 5.2, EndTime = 5.3, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 5.3, EndTime = 5.95, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 5.95, EndTime = 6.2, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 6.2, EndTime = 6.9, Type = "Red" },

                new ChartData { Date = "19.08.2019", StartTime = 6.9, EndTime = 6.95, Type = "Blue" },

                new ChartData { Date = "19.08.2019", StartTime = 6.95, EndTime = 17.95, Type = "Green" },

                ...

                new ChartData { Date = "20.08.2019", StartTime = 0, EndTime = 0.1, Type = "Blue" },

                new ChartData { Date = "20.08.2019", StartTime = 0.1, EndTime = 0.7, Type = "Red" },

                new ChartData { Date = "20.08.2019", StartTime = 0.7, EndTime = 1.2, Type = "Blue" },

                new ChartData { Date = "20.08.2019", StartTime = 1.2, EndTime = 2, Type = "Green" },

                ...

};

 

Is there any Syncfusion control that can achieve something like this?

If so, could you please provide an example?

 

Thank you for your help



BP Baby Palanidurai Syncfusion Team April 20, 2020 12:37 PM UTC

Hi Dominic, 

Thanks for your update. 

We have analyzed your query. You can bind those data which you provided in the last update to one series as like the below and for binding the color for each point from data source, you can use pointColorMapping, 
Code snippet: 
List<ChartData> chartData = new List<ChartData> 
            { 
                new ChartData { Date = "19.08.2019", StartTime = 0, EndTime = 1, Type = "Green" }, 
            .. . 
                new ChartData { Date = "20.08.2019", StartTime = 0, EndTime = 0.1, Type = "Blue" }, 
                ... 
}; 
            ViewBag.dataSource = chartData; 
 
 
 
<e-series-collection> 
      <e-series dataSource="ViewBag.dataSource" xName="Date" yName="EndTime" pointColorMapping="Type" type="@ChartSeriesType.StackingBar100"> 
                <e-series-animation enable="false"></e-series-animation> 
       </e-series> 
</e-series-collection> 

Screenshot: 
 
Since, you are providing start and end time duration in your data and if you want to bind those in a single series, there is rangecolumn series. In that, you can bind low and high value and bind start and end time those property. 
Code snippet: 
<e-series-collection> 
    <e-series dataSource="ViewBag.dataSource" xName="Date" low="StartTime" high="EndTime" pointColorMapping="Type" fill="lime" type="@ChartSeriesType.RangeColumn"> 
            <e-series-animation enable="false"></e-series-animation 
    </e-series> 
</e-series-collection> 


Kindly revert us, if you have any concerns. 

Regards, 
Baby.


DB Dominic Buerki April 21, 2020 05:12 AM UTC

Hey and thank you very much for this solution, its almost perfect now.

I have 2 little questions, i cant solve it by myself...

So i would like to have an 0-24 scale on the x-axis and for every hour a label as on the first image, is this possible because it is a 100 scale?

and the second question is, it is not possible o put a DateTime or TimeSpan into the ChartData like:

 List<ChartData> chartData = new List<ChartData>
            {
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,03,00,00),EndTime = new DateTime(2019,06,20,05,04,00,00),  Type = "Green" },
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,04,00,00),EndTime = new DateTime(2019,06,20,05,21,00,00),  Type = "Red" },
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,21,00,00),EndTime = new DateTime(2019,06,20,05,36,00,00),  Type = "Blue" },
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,36,00,00)EndTime = new DateTime(2019,06,20,05,42,00,00),  Type = "Red" }
.
.
.
                };


and so on?

Thanl you very much for your time and kindly regards
Dominic



SM Srihari Muthukaruppan Syncfusion Team April 23, 2020 03:47 AM UTC

Hi Dominic, 
  
We have analyzed your query. From that, we would like to let you know that in the bar chart x-axis doesn't support date-time Values. Hence we suggest using "load" and "axisLabelRender" event in the chart to achieve your requirement. Based on your requirement we have prepared a sample for your reference. Please find the sample, code snippet, and screenshot. 
  
  
Code Snippet: 
Index.cshtml: 
  
<div> 
    <ejs-chart id="myContainer" axisLabelRender="labelRender"  load="load" height="400"> 
        // add additional code here 
    </ejs-chart> 
</div> 
<script> 
    var count = 0; 
    function labelRender(args) { 
        if (args.axis.orientation === 'Horizontal') { 
            var chart = document.getElementById('myContainer').ej2_instances[0]; 
            if (count < 4) { 
                var date = new Date(chart.series[0].dataSource[count].StartTime).toUTCString(); 
                var dateObj = new Date(date); 
                var month = dateObj.getUTCMonth() + 1; //months from 1-12 
                var day = dateObj.getUTCDate(); 
                var year = dateObj.getUTCFullYear(); 
                var hours = dateObj.getUTCHours(); 
                var minutes = dateObj.getUTCMinutes(); 
                var seconds = dateObj.getUTCSeconds(); 
                count++; 
                args.text =  hours + ":" + minutes + ":" + seconds; 
            } else { 
                count = 0; 
                args.text = '' 
            } 
        } 
    } 
    function load(args) { 
        for (var i = 0; i < args.chart.series[0].dataSource.length; i++) { 
            args.chart.series[0].dataSource[i].StartTime = Date.parse(args.chart.series[0].dataSource[i].StartTime); 
        } 
    } 
</script> 

HomeController.Cs:
 
  
// add additional code here 
  
public IActionResult Index() 
        { 
            List<ChartData> chartData = new List<ChartData> 
            { 
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,03,00,00),EndTime = new DateTime(2019,06,20,05,04,00,00),  Type = "Green" }, 
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,04,00,00),EndTime = new DateTime(2019,06,20,05,21,00,00),  Type = "Red" }, 
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,21,00,00),EndTime = new DateTime(2019,06,20,05,36,00,00),  Type = "Blue" }, 
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,36,00,00),EndTime = new DateTime(2019,06,20,05,42,00,00),  Type = "Red" } 
            }; 
            ViewBag.dataSource = chartData; 
            return View(); 
        } 
        public class ChartData 
        { 
            public string Date { get; set; } 
  
            public DateTime StartTime { get; set; } 
  
            public DateTime EndTime { get; set; } 
  
            public string Type { get; set; } 
  
        } 
  
     
  
  
Screenshot: 
 
Let us know if you have any concerns. 
  
Regards, 
Srihari M 



DB Dominic Buerki April 23, 2020 11:24 AM UTC

Thanks for your answer,

i've tried a lot by myself now, but i cant get it to work.
the last example you sent, will show all bars with the same width, in the sample image u posted it will just double the width from bar to bar.
i wasn't abe to stretch them in relation to the duration...


Then I tried a previous Version you guys sent me.
There the problem is solved with the double values in the DataChart, this looks better, but the same problem appears there.
The width of the bars isn't scaling with the duration between start and end time.

The example is available as an attached file.

I would be verry grateful if you guys can help me to solve these problems in the solution i attached:

- Correct scaling of width of the bars
- DateTime values instead of double values

i need a view like this:


Thank you very much for your help.
Dominic


Attachment: stackingBarExample_5d2de1b2.zip


SM Srihari Muthukaruppan Syncfusion Team April 27, 2020 03:39 AM UTC

Hi Dominic,

We have analyzed your query. From that, we would like to let you know that we can achieve your requirements by providing the difference between the StartTime and EndTime to y values of the series. Based on your requirement we have prepared a sample for your reference. Please find the sample, code snippet, and screenshot. 
  
  
Code Snippet: 
Index.cshtml:
<div> 
    <ejs-chart id="myContainer" axisLabelRender="labelRender"  load="load" height="400"> 
        // add additional code here 
       <e-series-collection>
            <e-series dataSource="ViewBag.dataSource" xName="Date" yName="y" type="@ChartSeriesType.StackingBar100">
            </e-series>
        </e-series-collection>
    </ejs-chart> 
</div> 
<script> 
    var count = 0; 
    function labelRender(args) { 
        if (args.axis.orientation === 'Horizontal') { 
            var chart = document.getElementById('myContainer').ej2_instances[0]; 
            if (count < 4) { 
                var date = new Date(chart.series[0].dataSource[count].StartTime).toUTCString(); 
                var dateObj = new Date(date); 
                var month = dateObj.getUTCMonth() + 1; //months from 1-12 
                var day = dateObj.getUTCDate(); 
                var year = dateObj.getUTCFullYear(); 
                var hours = dateObj.getUTCHours(); 
                var minutes = dateObj.getUTCMinutes(); 
                var seconds = dateObj.getUTCSeconds(); 
                count++; 
                args.text =  hours + ":" + minutes + ":" + seconds; 
            } else { 
                count = 0; 
                args.text = '' 
            } 
        } 
    } 
    function load(args) { 
        for (var i = 0; i < args.chart.series[0].dataSource.length; i++) {
            args.chart.series[0].dataSource[i].y = Date.parse(args.chart.series[0].dataSource[i].EndTime) - Date.parse(args.chart.series[0].dataSource[i].StartTime);
        }
    } 
</script> 

HomeController.Cs:
 
  
// add additional code here 
  
public IActionResult Index() 
        { 
            List<ChartData> chartData = new List<ChartData> 
            { 
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,03,00,00),EndTime = new DateTime(2019,06,20,05,04,00,00),  Type = "Green" }, 
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,04,00,00),EndTime = new DateTime(2019,06,20,05,21,00,00),  Type = "Red" }, 
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,21,00,00),EndTime = new DateTime(2019,06,20,05,36,00,00),  Type = "Blue" }, 
                new ChartData { Date ="20.06.2019", StartTime = new DateTime(2019,06,20,05,36,00,00),EndTime = new DateTime(2019,06,20,05,42,00,00),  Type = "Red" } 
            }; 
            ViewBag.dataSource = chartData; 
            return View(); 
        } 
        public class ChartData 
        { 
            public string Date { get; set; } 
  
            public DateTime StartTime { get; set; } 
  
            public DateTime EndTime { get; set; } 
            
            public DateTime y { get; set; }
  
            public string Type { get; set; } 
  
        } 
  
     
  
  
Screenshot: 
 
Let us know if you have any concerns. 
  
Regards, 
Srihari M 


Loader.
Up arrow icon