My Json data is structured like this:
var d = "1,3,2,4"
I want to convert it to:
var d = [3,5,3,6]
I attempted the following:
success: function (Response) {
debugger;
var du = (Response.d);
var final_string = '[' + du + ']'
// final_string = [1, 3, 2, 4];
console.log(final_string);
However, my solution is not working as intended. I need the value of final_string
to be final_string = [1, 3, 2, 4];
I am using this data to create a graph
JavaScript
<script>
$(document).ready(function(){
debugger;
$.ajax({
type: "Post",
url: "Default.aspx/getdata",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (Response) {
debugger;
var d = Response.d.toString();
var final_string = '[' + d + ']'
console.log(final_string);
//final_string = [1,3,2,4];
var options = {
chart: {
height: 250,
width:500,
type: 'line',
},
series: [{
name: ' ',
type: 'column',
data: final_string
}, {
name: '',
type: 'line',
data: final_string
}],
stroke: {
width: [0, 4]
},
title: {
text: 'Total Count'
},
labels: ['Birthady', 'Anniversary', 'Special', 'Total'],
xaxis: {
type: 'text'
},
yaxis: [{
title: {
text: 'Count Blog',
},
}, {
opposite: true,
title: {
text: ''
}
}]
}
debugger;
var chart = new ApexCharts(
document.querySelector("#chart"),
options
);
chart.render();
},
error: function (result) {
}
});
});
</script>
The correct data format for the series is [1,3,2,4]
. When I pass data = [1,3,2,4]
in the series data, the graph displays correctly. But when I pass final_string
in the series data, the graph does not display correctly. Can anyone help me with this issue?