Hi all, my chart renders good when i use the $get method like below, where path to the CSV file is explicitly mention in the url of $.get
$.get(“/files/ReloadedOIFiles/BankNiftyOptionChain_todisplayinchart.csv” , getDataPointsFromCSV);
csv file has data like
Jul 12 2019,11:44:23,30647.6,1402680,986080,409059,884740,478260,346442,755501,-507820
Jul 12 2019,11:44:53,30642.2,1402680,986080,409842,884740,478260,346911,756753,-507820
……
but when $.get invokes servlet , even though the servlet sends String data with data format as in csv, and the window.alert successfully gives the lines and the values that are split with coma, chart rendering is not happening.
below is the code.
$.get(“LoadLiveChart”,{TradingDate:tradingDate,LowerStrike:lowerStrike,UpperStrike:upperStrike,LastLine:lastLine} , getDataPointsFromCSV);
var chart1 = new CanvasJS.Chart(“chartContainer1”, {
animationEnabled: true,
exportEnabled: true,
title:{
text: “Bank Nifty Index ”
},
axisX:{
title: “Time”,
crosshair: {
enabled: true,
snapToDataPoint: true
}
},
axisY: {
title: “Bank Nifty Index”,
includeZero: false,
crosshair: {
enabled: true,
snapToDataPoint: true}
},
data: [{
type: “line”,
axisYType: “primary”,
toolTipContent: “{y} Bank Nifty Index”,
dataPoints: dataPoints1
}]
});
function getDataPointsFromCSV(csv) {
var csvLines = points = [];
csvLines = csv.split(/[\r?\n|\r|\n]+/);
for (var i = 0; i < csvLines.length; i++) {
if (csvLines[i].length > 0) {
window.alert(csvLines[i]);
points = csvLines[i].split(“,”);
dataPoints1.push({
label: points[1],
y: parseInt(points[2])
});
}
}
chart1.render();
}
It would be of great help if some one helps me in this case as i have spent many hours trying to make it work.I even tried with JSON, but the chart does not render even then. is there anything i am missing with $.get