santhoshj
Posts: 6
Joined: Tue Jun 01, 2021 1:15 pm

Scatter plot forEach chart statement not updating the series

Hi All,

I am facing issue in updating all the charts series using for Each statement as shown below:
console.log(arr) 0: "00796"
1: "0.00"
2: "4.18"
3: "0.00"
4: "0.00"
5: "3.62"
6: "0.00"
7: "0.00"
8: "3.59"
9: "0.00"
10: "0.00"
11: "1.22"
12: "0.00"
length: 13
__proto__: Array(0)

for(var line = 2; line < lines.length; line++){

arr = lines[line].split(",");

//console.log(arr);
charts.forEach((chart, i) => {
chart.series[0].addPoint([parseFloat(arr[3*i+2]),parseFloat(arr[3*i+1])],false);
});
charts.forEach((chart, i) => {
chart.series[1].addPoint([parseFloat(arr[3*i+2]),parseFloat(arr[3*i+3])],false);

});

}
Instead of updating all the charts with different elements of array, same values is stored in all the chart series.

Kindly let me know where am I missing the index. Appreciate any assistance.
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: Scatter plot forEach chart statement not updating the series

Hello! Welcome to the official highcharts forum, and thanks for contacting us with your question!
Could you reproduce your issue in an online editor? You can start here: https://jsfiddle.net/BlackLabel/9b1p5vkn/

Kind regards,
Paweł Lysy
Highcharts Developer
santhoshj
Posts: 6
Joined: Tue Jun 01, 2021 1:15 pm

Re: Scatter plot forEach chart statement not updating the series

I have uploaded my code to https://jsfiddle.net/46k5w8ve/1/ please let me know whether you could access it or not. Note that the data will be fetched from the text file with the following content.

Seq,I1,V1,P1,I2,V2,P2,I3,V3,P3,I4,V4,P4,
00004,444.00,0.20,90.60,432.00,0.20,89.60,444.00,0.20,92.20,460.00,0.09,43.00
00008,444.00,0.23,103.80,432.00,0.23,100.40,440.00,0.23,101.00,460.00,0.10,46.00
00012,440.00,0.25,111.00,432.00,0.25,108.40,444.00,0.25,111.00,452.00,0.10,47.80
00016,444.00,0.27,123.20,432.00,0.27,117.40,440.00,0.27,118.00,460.00,0.11,51.00
00018,440.00,0.29,127.00,436.00,0.28,122.20,440.00,0.28,123.00,460.00,0.11,52.00
00022,444.00,0.31,139.60,432.00,0.30,130.40,436.00,0.30,130.00,452.00,0.12,55.40
00026,444.00,0.33,150.20,428.00,0.32,137.60,436.00,0.32,139.00,456.00,0.12,58.80
00030,440.00,0.36,159.00,436.00,0.34,149.40,440.00,0.34,149.00,456.00,0.13,61.40
00032,440.00,0.37,163.00,432.00,0.35,152.80,436.00,0.35,152.00,456.00,0.13,62.60
00036,440.00,0.39,175.00,436.00,0.37,163.40,440.00,0.37,163.00,460.00,0.14,66.00
00040,448.00,0.42,189.60,432.00,0.39,171.20,440.00,0.39,172.00,460.00,0.15,69.00
00044,440.00,0.44,196.00,432.00,0.41,179.20,444.00,0.41,183.60,452.00,0.15,70.20
00048,444.00,0.46,207.20,432.00,0.43,188.20,432.00,0.43,187.80,460.00,0.16,74.00
00052,444.00,0.49,219.60,432.00,0.45,197.60,440.00,0.45,200.00,460.00,0.17,78.00
00054,444.00,0.50,223.60,432.00,0.46,202.60,436.00,0.46,202.40,452.00,0.17,77.40
00058,448.00,0.53,237.00,432.00,0.49,211.00,436.00,0.48,211.60,456.00,0.17,81.80
00062,440.00,0.55,243.00,436.00,0.51,222.00,444.00,0.50,225.20,456.00,0.18,84.60
00066,444.00,0.57,255.40,436.00,0.53,231.20,440.00,0.52,232.00,456.00,0.19,87.20
00070,444.00,0.60,268.60,436.00,0.55,240.20,436.00,0.54,238.80,456.00,0.20,91.00
00072,444.00,0.61,273.40,436.00,0.56,245.40,436.00,0.56,244.00,456.00,0.20,91.00
00076,440.00,0.64,281.00,432.00,0.58,252.80,440.00,0.58,256.00,456.00,0.20,94.80
00080,444.00,0.66,294.60,432.00,0.60,260.80,436.00,0.60,262.20,460.00,0.21,99.00
00084,448.00,0.68,307.80,428.00,0.62,267.80,440.00,0.62,275.00,460.00,0.22,102.00
00086,440.00,0.69,307.00,436.00,0.63,277.60,440.00,0.63,278.00,452.00,0.22,102.20
00090,448.00,0.72,325.80,432.00,0.66,285.00,436.00,0.65,286.60,456.00,0.23,104.00
00094,444.00,0.75,333.80,436.00,0.68,296.00,444.00,0.67,300.40,456.00,0.23,108.80
00114,444.00,0.87,388.60,436.00,0.78,342.60,440.00,0.78,344.00,452.00,0.27,122.40
00116,448.00,0.88,396.80,432.00,0.79,344.60,440.00,0.79,349.00,456.00,0.27,125.60
00120,444.00,0.91,404.80,432.00,0.81,353.60,448.00,0.81,365.80,456.00,0.28,127.00
00124,444.00,0.93,414.60,432.00,0.84,362.00,440.00,0.83,368.00,460.00,0.28,132.00
00126,440.00,0.95,418.00,432.00,0.85,368.40,444.00,0.84,376.20,460.00,0.29,133.00
00130,444.00,0.97,431.80,432.00,0.87,376.40,440.00,0.87,382.00,452.00,0.29,134.60
00134,448.00,0.99,447.40,432.00,0.89,386.80,436.00,0.89,388.00,456.00,0.30,139.60
00138,444.00,1.02,455.40,440.00,0.91,403.00,444.00,0.91,405.60,460.00,0.31,142.00
00140,444.00,1.03,459.40,432.00,0.92,400.20,440.00,0.92,406.00,456.00,0.31,144.60
00144,448.00,1.06,475.60,436.00,0.94,413.80,444.00,0.94,419.60,460.00,0.32,148.00
00148,448.00,1.08,485.20,432.00,0.97,419.00,436.00,0.96,422.80,460.00,0.33,151.00
00150,440.00,1.09,483.00,432.00,0.98,423.00,436.00,0.97,426.80,460.00,0.33,153.00
00154,448.00,1.12,503.20,432.00,1.00,432.40,440.00,1.00,440.00,456.00,0.34,155.00
00158,440.00,1.14,505.00,436.00,1.02,446.40,436.00,1.02,444.00,460.00,0.34,159.00
00160,448.00,1.16,519.00,432.00,1.03,446.80,436.00,1.03,449.00,456.00,0.35,159.00
00164,440.00,1.18,521.00,436.00,1.05,460.60,444.00,1.05,466.00,460.00,0.36,165.00
00168,444.00,1.21,538.80,436.00,1.07,470.80,440.00,1.07,472.00,456.00,0.36,165.20
00172,444.00,1.23,548.40,432.00,1.10,475.00,444.00,1.09,486.40,456.00,0.37,169.20
00174,448.00,1.24,559.40,428.00,1.11,475.00,440.00,1.10,487.00,456.00,0.37,171.60
00178,444.00,1.27,566.40,436.00,1.13,493.20,440.00,1.12,496.00,464.00,0.38,176.00
00182,444.00,1.29,576.20,432.00,1.15,497.40,440.00,1.15,506.00,452.00,0.39,176.00
00204,452.00,1.43,649.60,432.00,1.27,550.80,440.00,1.27,558.00,456.00,0.42,195.80
00206,444.00,1.45,643.00,436.00,1.28,559.40,440.00,1.28,564.00,460.00,0.43,197.00
00210,444.00,1.47,655.40,432.00,1.30,564.20,440.00,1.30,573.00,456.00,0.43,199.80
00214,448.00,1.50,672.00,436.00,1.32,579.80,444.00,1.32,588.40,460.00,0.44,204.00
00216,444.00,1.51,672.60,436.00,1.33,583.80,444.00,1.33,594.20,460.00,0.44,206.00
00220,444.00,1.53,682.20,432.00,1.36,587.00,440.00,1.35,597.00,460.00,0.45,209.00
00224,448.00,1.56,699.60,432.00,1.38,597.80,440.00,1.38,607.00,460.00,0.46,214.00
00226,448.00,1.57,705.20,436.00,1.39,607.40,436.00,1.39,606.00,456.00,0.47,214.00
00230,452.00,1.60,723.00,432.00,1.41,611.20,440.00,1.41,622.00,456.00,0.47,216.40
00234,440.00,1.63,717.00,436.00,1.43,626.80,444.00,1.43,637.40,460.00,0.48,220.00
00238,448.00,1.65,740.60,436.00,1.46,636.00,440.00,1.45,640.00,460.00,0.48,224.00
00240,448.00,1.66,745.20,432.00,1.47,635.00,444.00,1.47,652.00,460.00,0.49,227.00
00244,448.00,1.68,756.40,432.00,1.49,644.40,444.00,1.49,663.60,460.00,0.50,231.00
00248,444.00,1.71,761.40,436.00,1.51,660.40,440.00,1.51,666.00,464.00,0.50,234.40
00250,448.00,1.72,774.40,432.00,1.52,659.20,440.00,1.52,671.00,460.00,0.51,235.00
00254,444.00,1.75,778.60,436.00,1.54,674.80,448.00,1.54,692.80,464.00,0.51,240.20
00258,444.00,1.78,790.00,436.00,1.57,684.00,444.00,1.56,694.60,460.00,0.52,242.00
00262,444.00,1.80,802.20,436.00,1.59,694.20,440.00,1.59,699.00,456.00,0.53,242.20
00266,444.00,1.83,813.80,432.00,1.61,698.20,444.00,1.61,715.80,464.00,0.54,250.00
00296,444.00,2.02,899.40,436.00,1.78,776.20,440.00,1.78,783.00,456.00,0.59,272.80
00298,440.00,2.04,897.00,436.00,1.79,782.40,440.00,1.79,788.00,464.00,0.60,279.80
00302,448.00,2.06,925.80,432.00,1.81,784.20,444.00,1.81,805.60,460.00,0.60,279.00
00306,452.00,2.09,947.20,432.00,1.84,794.00,440.00,1.83,807.00,460.00,0.61,281.00
00310,448.00,2.12,950.60,436.00,1.86,811.20,444.00,1.86,825.00,460.00,0.62,286.00
00312,448.00,2.13,955.60,436.00,1.87,817.40,440.00,1.87,823.00,460.00,0.62,287.00
00316,448.00,2.15,966.40,428.00,1.89,811.80,444.00,1.89,840.80,464.00,0.63,295.40
00320,452.00,2.18,987.80,432.00,1.91,828.60,444.00,1.91,850.40,460.00,0.64,295.00
00322,448.00,2.20,985.00,432.00,1.92,832.60,440.00,1.92,848.00,456.00,0.64,293.40
00326,448.00,2.22,996.20,432.00,1.95,843.40,444.00,1.94,864.20,460.00,0.65,299.00
00330,444.00,2.25,999.00,440.00,1.97,868.00,444.00,1.97,875.80,464.00,0.66,306.00
00334,448.00,2.27,1019.80,432.00,1.99,863.60,444.00,1.99,885.60,460.00,0.66,306.00
00336,452.00,2.29,1035.40,436.00,2.01,876.00,448.00,2.00,896.60,464.00,0.67,310.00
00340,448.00,2.31,1038.40,436.00,2.03,885.20,448.00,2.03,909.00,464.00,0.67,313.40
00344,444.00,2.34,1039.80,436.00,2.05,895.40,444.00,2.05,910.00,464.00,0.68,319.20
00346,452.00,2.35,1064.20,432.00,2.06,891.80,444.00,2.06,915.80,464.00,0.69,321.80
00350,444.00,2.38,1058.60,440.00,2.08,918.00,444.00,2.08,924.80,464.00,0.69,322.40
00354,448.00,2.40,1078.40,436.00,2.11,919.00,440.00,2.10,926.00,460.00,0.70,323.00
00356,448.00,2.42,1085.60,436.00,2.12,925.20,448.00,2.12,949.00,468.00,0.71,332.00
00360,452.00,2.44,1106.60,436.00,2.14,934.40,444.00,2.14,950.00,464.00,0.71,332.40
00364,448.00,2.47,1109.80,436.00,2.16,944.60,448.00,2.16,969.20,460.00,0.72,333.00
00368,448.00,2.49,1119.40,436.00,2.18,953.80,440.00,2.18,960.00,464.00,0.73,340.60
00392,448.00,2.65,1189.80,436.00,2.32,1013.40,448.00,2.31,1037.80,460.00,0.78,358.00
00394,448.00,2.66,1195.40,440.00,2.33,1027.00,448.00,2.32,1042.40,468.00,0.78,366.20
00398,448.00,2.69,1207.80,436.00,2.36,1028.00,444.00,2.35,1043.00,464.00,0.79,366.00
00402,448.00,2.72,1220.20,436.00,2.38,1038.20,452.00,2.37,1073.80,468.00,0.79,372.80
00406,448.00,2.75,1232.60,436.00,2.40,1048.40,440.00,2.39,1055.00,456.00,0.80,365.20
00408,444.00,2.76,1227.60,436.00,2.41,1053.60,444.00,2.41,1070.00,464.00,0.80,373.60
00412,448.00,2.79,1250.60,436.00,2.43,1062.80,444.00,2.43,1079.80,460.00,0.81,373.00
00416,448.00,2.81,1261.80,436.00,2.46,1073.20,444.00,2.45,1088.80,460.00,0.82,377.00
00418,452.00,2.82,1277.20,436.00,2.47,1077.20,448.00,2.46,1103.20,464.00,0.82,384.20
00422,448.00,2.85,1278.20,440.00,2.49,1097.00,448.00,2.49,1115.00,460.00,0.83,385.00
00426,452.00,2.88,1301.00,436.00,2.51,1096.60,448.00,2.51,1125.60,464.00,0.84,390.80
00430,452.00,2.91,1316.40,432.00,2.54,1097.00,444.00,2.53,1125.60,460.00,0.85,391.00
00432,448.00,2.92,1309.60,436.00,2.55,1112.20,444.00,2.54,1129.60,460.00,0.85,392.00
00436,448.00,2.94,1320.40,432.00,2.57,1112.20,440.00,2.56,1129.00,456.00,0.86,392.00
00440,448.00,2.97,1332.20,440.00,2.59,1143.00,448.00,2.58,1159.40,468.00,0.87,407.00
00444,452.00,3.00,1357.80,440.00,2.62,1152.00,444.00,2.61,1159.80,460.00,0.87,402.00
00446,448.00,3.01,1351.80,436.00,2.63,1146.00,448.00,2.62,1175.20,468.00,0.88,411.00
00450,448.00,3.03,1361.40,436.00,2.65,1156.20,440.00,2.64,1164.00,460.00,0.89,409.00
00454,444.00,3.06,1362.20,440.00,2.67,1177.00,444.00,2.66,1184.20,464.00,0.89,415.40
00482,444.00,3.24,1441.40,432.00,2.83,1223.40,440.00,2.82,1241.00,456.00,0.95,434.20
00486,440.00,3.27,1440.00,432.00,2.85,1232.80,444.00,2.84,1262.60,452.00,0.95,433.60
00490,440.00,3.29,1450.00,432.00,2.87,1242.20,436.00,2.86,1250.80,448.00,0.96,430.60
00492,436.00,3.31,1443.00,436.00,2.88,1258.60,436.00,2.87,1254.80,444.00,0.96,428.40
00496,432.00,3.33,1440.80,408.00,2.90,1186.40,408.00,2.89,1182.40,392.00,0.97,381.80
00498,412.00,3.35,1380.00,392.00,2.92,1144.00,384.00,2.91,1117.00,356.00,0.97,348.80
00502,356.00,3.37,1200.20,316.00,2.94,929.00,308.00,2.93,903.60,268.00,0.99,265.60
00506,268.00,3.39,909.20,232.00,2.96,687.40,220.00,2.95,649.00,184.00,0.99,183.40
00510,180.00,3.42,615.00,148.00,2.98,441.60,140.00,2.97,416.00,104.00,1.00,104.60
00530,0.00,3.54,0.00,0.00,3.08,0.00,0.00,3.07,0.00,0.00,1.03,0.00
00532,0.00,3.55,0.00,0.00,3.09,0.00,0.00,3.08,0.00,0.00,1.04,0.00
santhoshj
Posts: 6
Joined: Tue Jun 01, 2021 1:15 pm

Re: Scatter plot forEach chart statement not updating the series

Hi All,

Kindly refer this link -> https://jsfiddle.net/3qxsjmkt/1/ which contains both version of data handling i.e. by file upload as well as raw data input.

Sorry for posting error code.
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: Scatter plot forEach chart statement not updating the series

Hi! You posted a lot of code in there. I don't really understand what is the issue, and how to use this part of code. Could you again try to explain what is the issue, and strap the code in there from useless parts of code, that don't affect your problem? Thanks! Kind regards
Paweł Lysy
Highcharts Developer
santhoshj
Posts: 6
Joined: Tue Jun 01, 2021 1:15 pm

Re: Scatter plot forEach chart statement not updating the series

Okay. The program contains data for the scatter plot. I have removed most of the it and only kept critical points. I am pasting the code here for review. https://jsfiddle.net/6p2geurL/

Issue - Ideally, all the four should have distinct data to plot. But the data is the first scatter plot is copied at difference scale in the rest of the plots.

Data

["Seq,mm,date,hh,mm,ss,I1,V1,P1,I2,V2,P2,I3,V3,P3,I4,V4,P4,Temp, Humidity,UV,Visible,IR", "00001,0602164126,192.00,0.80,155.60,228.00,1.29,295.20,240.00,0.90,216.00,112.00,0.28,32.20,3.91,37.11,58.28,0,0,0",
//Seq, I1,V1,P1,I2,V2,P2,I3,V3,P3,I4,V4,P4
"00020,148.00,0.19,28.00,156.00,0.18,28.40,172.00,0.18,32.60,144.00,0.08,12.20", "00444,144.00,2.73,393.80,152.00,2.37,361.20,164.00,2.36,388.20,140.00,0.79,111.00", "00450,140.00,2.76,387.00,152.00,2.40,366.60,168.00,2.39,402.40,140.00,0.80,112.00", "00456,140.00,2.80,392.00,152.00,2.44,370.00,168.00,2.43,408.00,140.00,0.81,114.00", "00460,136.00,2.83,384.00,156.00,2.46,383.00,168.00,2.45,412.20,136.00,0.82,112.40", "00466,136.00,2.87,390.00,152.00,2.49,378.40,168.00,2.48,417.80,140.00,0.83,117.00", "00472,140.00,2.90,406.00,152.00,2.52,383.80,172.00,2.51,432.20,144.00,0.84,121.40", "00476,140.00,2.92,409.00,152.00,2.54,386.80,164.00,2.53,416.20,140.00,0.85,119.00", "00482,140.00,2.96,414.00,152.00,2.57,391.20,168.00,2.56,431.80,140.00,0.86,121.00", "00486,144.00,2.99,430.80,152.00,2.59,394.60,164.00,2.59,424.00,140.00,0.87,122.00", "00506,140.00,3.11,435.00,148.00,2.70,399.60,168.00,2.69,452.20,144.00,0.90,130.20", "00512,136.00,3.15,429.60,152.00,2.73,415.80,164.00,2.72,447.20,140.00,0.91,127.00", "00516,136.00,3.17,431.60,156.00,2.75,429.60,164.00,2.74,450.40,136.00,0.92,125.60", "00522,136.00,3.21,436.20,152.00,2.78,423.20,168.00,2.77,466.80,136.00,0.93,127.40", "00526,140.00,3.23,453.00,148.00,2.80,415.40,168.00,2.79,470.40,140.00,0.94,131.00", "00532,140.00,3.27,458.00,152.00,2.83,431.60,160.00,2.83,452.00,140.00,0.95,133.00", "00536,140.00,3.29,461.00,144.00,2.86,411.00,164.00,2.85,467.00,140.00,0.96,134.00", "00542,136.00,3.33,453.40,140.00,2.89,404.00,152.00,2.88,437.00,132.00,0.97,128.00", "00548,100.00,3.36,336.00,92.00,2.92,268.40,96.00,2.91,279.00,88.00,0.98,86.20", "00552,60.00,3.39,203.00,44.00,2.94,129.80,48.00,2.93,140.60,40.00,0.99,39.00",
"00558,4.00,3.43,13.00,0.00,2.97,0.00,4.00,2.96,11.80,0.00,1.00,0.00",
"00564,0.00,3.46,0.00,0.00,3.00,0.00,0.00,2.99,0.00,0.00,1.01,0.00",
"00796,0.00,4.17,0.00,0.00,3.59,0.00,0.00,3.61,0.00,0.00,1.22,0.00", ""]

V1 I1 and V1 P1 should be stored in chart[0], V2 I2 and V2 P2 should be stored in chart[1]
Problem storing the data in the charts.
for(var line = 2; line < lines.length; line++){

arr = lines[line].split(",");

charts.forEach((chart, j) => chart.series[0].addPoint([parseFloat(arr[3*j+2]),parseFloat(arr[3*j+1])],false));
charts.forEach((chart, j) => chart.series[1].addPoint([parseFloat(arr[3*j+2]),parseFloat(arr[3*j+3])],false));

}
chart.redraw();

Same data is plotted for 4 different charts.
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: Scatter plot forEach chart statement not updating the series

OK! So first of all, we do have the data module, which makes loading the data much easier. Check the API reference, and let me know if you could find something for yourself: https://api.highcharts.com/highcharts/data
Now, coming to your code. The code that you are loading is much like the CSV data. Unfortunately, the data, that gets loaded by the data module is used for only 1 chart, but you can use the module as a separate function, and then you can add the series to correct chart. In this demo I did something like that: https://jsfiddle.net/BlackLabel/487ocwxa/

What you need to do, is just apply correct settings to the data module, so that your configuration will be correctly parsed. Let me know, if that works for you, and don't hesitate to ask any further questions!
https://jsfiddle.net/BlackLabel/s5yu7gf6/

Kind regards,
Paweł Lysy
Highcharts Developer
santhoshj
Posts: 6
Joined: Tue Jun 01, 2021 1:15 pm

Re: Scatter plot forEach chart statement not updating the series

Hi,

Data module is very useful for handling csv files.

Is there any way to select the x-axis for charts other than the default first column?

Kindly let me know.
santhoshj
Posts: 6
Joined: Tue Jun 01, 2021 1:15 pm

Re: Scatter plot forEach chart statement not updating the series

Hi Pawel,

Original issue is still unresolved. chart redraw is not working. Even after adding points to individual series of each charts, I am unable to trace what is causing the charts data.
santhoshj wrote: Hi All,

Kindly refer this link -> https://jsfiddle.net/3qxsjmkt/1/ which contains both version of data handling i.e. by file upload as well as raw data input.

Sorry for posting error code.
pawelys
Posts: 962
Joined: Wed Sep 02, 2020 10:37 am

Re: Scatter plot forEach chart statement not updating the series

I don't understand what you mean by 'what is causing the charts data'. Could you elaborate?
You can set the https://api.highcharts.com/highcharts/data.startColumn option, to set, from which column you should start parsing, or use the https://api.highcharts.com/highcharts/data.columns callback function to switch places. Kind regards,
Paweł Lysy
Highcharts Developer

Return to “Highcharts Usage”