Below is the HighCharts JS code snippet that I have integrated into my aspx page:
Highcharts.chart('highcharts1', {
chart: {
type: 'bar'
},
title: {
text: 'Number of MSMEs By District',
align: 'left'
},
xAxis: {
categories: JSON.parse(jsonDistrict),
title: {
text: null
},
gridLineWidth: 1,
lineWidth: 0
},
yAxis: {
min: 0,
title: {
text: 'Population (millions)',
align: 'high'
},
labels: {
overflow: 'justify'
},
gridLineWidth: 0
},
tooltip: {
valueSuffix: ' millions'
},
plotOptions: {
bar: {
borderRadius: '50%',
dataLabels: {
enabled: true
},
groupPadding: 0.1
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 80,
floating: true,
borderWidth: 1,
backgroundColor:
Highcharts.defaultOptions.legend.backgroundColor || '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Year 1990',
data: [631, 727, 3202, 721]
}, {
name: 'Year 2000',
data: [814, 841, 3714, 726]
}, {
name: 'Year 2018',
data: [1276, 1007, 4561, 746]
}]
});
I sourced this code from the official HighCharts website to display a static dataset in the chart. However, I am now working on making the chart dynamic by fetching district names and counts from a PLSQL database.
protected string BindDataToChart()
{
DataTable dt = objBO.Get_MSME_Chart_Data(new object[] { null });
List<string> districtName = new List<string>();
foreach(DataRow row in dt.Rows)
{
districtName.Add(row["DISTRICT_NAME"].ToString());
}
string jsonDistrict = JsonConvert.SerializeObject(districtName, Formatting.Indented);
return jsonDistrict;
}
I have been struggling to pass the dynamically generated district names from CS file to append to the JavaScript code's xAxis Categories section. Additionally, I plan to implement similar dynamic data for the series data in the chart.
I appreciate any assistance provided, thank you for your help.