|
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();
} |
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
|
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> |
|
<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> |
|
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; } }
|
|
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) { 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; } }
|