I've data grouping in C#
and trying to bind it from Razor
view as follows with high charts:
//Dynamic Chart - Starts
@if (Model.aLstTopsideModuleGroupBy.ToList().Count > 0)
{
foreach (var item in Model.aLstTopsideModuleGroupBy)
{
foreach (var item2 in item)
{
int i = 0;
<text>
Highcharts.chart('container'@i, {
chart: {
type: 'column'
},
title: {
text: 'Demo Chart'
},
subtitle: {
text: ''
},
xAxis: {
categories: [
'Structural Primary',
'Structural Secondary',
'Mechanical',
'Piping',
'Electrical',
'Instrument',
'Telecommunication',
'Safety',
'Architectural ',
'Other/ Future Load ',
'Live Load'
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Weight Data'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y:.1f}</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0
}
},
series: [
{
name: 'Dry',
data: '@item2.BaseDry'
}, {
name: 'Operating',
data: '@item2.BaseOp'
}]
});
</text>
i++;
}
}
}
//Dynamic Chart - Ends
The data grouping is something as follows:
Data 1
1, 2, 3, 4, 5
Data 2
1, 2, 3, 4, 5
The above I require to create two different charts depending upon the data set, that's why used the followg:
Highcharts.chart('container'@i, {});
In the frontend, trying to do the following:
<div class="container-fluid">
<div class="row">
<div class="col-sm-12 col-lg-12 col-md-12 col-xs-12">
@if (Model.aLstTopsideModuleGroupBy.ToList().Count > 0)
{
int i = 0;
foreach (var item in Model.aLstTopsideModuleGroupBy)
{
<div id="container" @i></div>
<p class="highcharts-description">
</p>
}
i++;
}
</div>
</div>
</div>
In the browser's inspect element, getting this exception:
Uncaught SyntaxError: missing ) after argument list
I was trying to follow this link but failed - Razor With JavaScript
Is there any way I can make the chart dynamic with Razor
view rather Ajax
call? This is what I am trying to implement: