I would like to create a line plot where x-axis tick labels start from 12:00 to 00:00 and ends at 11:59. My data sorted so that TIME starts from 12:00 and ends at 11:59. This is the plot I end up: 
I am not sure why the straight line, and the line on the left axis of line plot pops up. How can I solve this issue? I expect to see the line plot, x-axis represents TIME column and starts from 12:00, and ends at 11:59. The line should be nice.
To solve thiss issue, I changed the xAxis domain to .domain([parseTime("12:00:00"), parseTime("23:59:00")]) But that weird straight line and lefgt line of theplot pops. up. I appreciate any hints.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>D3 CSV Example</title>
<script src="https://d3js.org/d3.v7.min.js"></script>
<style>
/* LINE CHART */
.line {
fill: none;
stroke: #ed3700;
}
</style>
</head>
<body>
<h1>D3 CSV Example</h1>
<script>
// Set up the SVG container
const svgWidth = 600;
const svgHeight = 400;
const margin = { top: 20, right: 30, bottom: 40, left: 50 };
const chartWidth = svgWidth - margin.left - margin.right;
const chartHeight = svgHeight - margin.top - margin.bottom;
const svg = d3
.select("body")
.append("svg")
.attr("width", svgWidth)
.attr("height", svgHeight);
const chart = svg
.append("g")
.attr("transform", `translate(${margin.left}, ${margin.top})`);
// Load the data from CSV
d3.csv("reordered_synthetic_data.csv").then(function (data) {
// Parse the date string and extract only the time as hours and minutes
const parseTime = d3.timeParse("%H:%M:%S");
// Convert data types
data.forEach(function (d) {
d.TIME = parseTime(d.TIME);
d.VALUE1 = +d.VALUE1;
d.INSPECTION = +d.INSPECTION;
});
let visit1 = data.filter(d => d.INSPECTION == 1);
// Set up scales
const xScale = d3
.scaleTime()
.domain([parseTime("12:00:00"), parseTime("23:59:00")]) // Set the domain manually
.range([0, chartWidth]);
const yScale = d3
.scaleLinear()
.domain([0, 180])
.range([chartHeight, 0]);
// Set up axes
const xAxis = d3.axisBottom(xScale)
.tickFormat(d3.timeFormat("%H:%M")); // Format the tick labels to display hour:minute
const yAxis = d3.axisLeft(yScale);
// Add axes to the chart
chart
.append("g")
.attr("class", "x-axis")
.attr("transform", `translate(0, ${chartHeight})`)
.call(xAxis);
chart.append("g").attr("class", "y-axis").call(yAxis);
// Define the line function
const line = d3
.line()
.x((d) => xScale(d.TIME))
.y((d) => yScale(d.VALUE1));
// Draw the line chart
chart
.append("path")
.datum(visit1)
.attr("class", "line")
.attr("d", line);
});
</script>
</body>
</html>
You can find my CSV file:
DATE_TIME,ID,HOUR,MINUTE,VALUE1,VALUE2,TIME,INSPECTION,seconds
2018-11-01 12:00:00,1,12,0,82.4818356370727,87.65532538616083,12:00:00,1,720
2018-11-01 12:20:00,1,12,20,114.36084687826856,89.76606638044296,12:20:00,1,740
2018-11-01 12:40:00,1,12,40,149.2745234585085,78.59914264907545,12:40:00,1,760
2018-11-01 13:00:00,1,13,0,118.46198153923852,71.602023294704,13:00:00,1,780
2018-11-01 13:20:00,1,13,20,113.47363946789812,82.9802315554754,13:20:00,1,800
2018-11-01 13:40:00,1,13,40,124.52765200932272,79.25241460867473,13:40:00,1,820
2018-11-01 14:00:00,1,14,0,144.94079558959947,65.9708531211893,14:00:00,1,840
2018-11-01 14:20:00,1,14,20,154.4860403982185,62.47993589006475,14:20:00,1,860
2018-11-01 14:40:00,1,14,40,103.05095426442168,79.12278561261758,14:40:00,1,880
2018-11-01 15:00:00,1,15,0,88.71000005665377,72.63269391153845,15:00:00,1,900
2018-11-01 15:20:00,1,15,20,118.38725463585833,68.35955256035255,15:20:00,1,920
2018-11-01 15:40:00,1,15,40,90.35575706090954,84.996720275759,15:40:00,1,940
2018-11-01 16:00:00,1,16,0,119.53679642856682,64.48688419793011,16:00:00,1,960
2018-11-01 16:20:00,1,16,20,135.27829999848916,74.48257447199506,16:20:00,1,980
2018-11-01 16:40:00,1,16,40,155.48291761113225,83.72128851838752,16:40:00,1,1000
2018-11-01 17:00:00,1,17,0,85.96341780030743,87.73333389566491,17:00:00,1,1020
2018-11-01 17:20:00,1,17,20,148.20928658532694,68.51872403107251,17:20:00,1,1040
2018-11-01 17:40:00,1,17,40,112.90401161612893,78.71422067548829,17:40:00,1,1060
2018-11-01 18:00:00,1,18,0,87.24314271333824,85.14578512967933,18:00:00,1,1080
2018-11-01 18:20:00,1,18,20,159.98777892013288,73.91122953488058,18:20:00,1,1100
2018-11-01 18:40:00,1,18,40,134.132508027465,62.87714757838526,18:40:00,1,1120
2018-11-01 19:00:00,1,19,0,93.8475785922444,85.87709920539899,19:00:00,1,1140
2018-11-01 19:20:00,1,19,20,87.96494807670916,64.32810207816041,19:20:00,1,1160
2018-11-01 19:40:00,1,19,40,96.85350185792925,87.67564666896372,19:40:00,1,1180
2018-11-01 20:00:00,1,20,0,150.49329018102594,75.28292350135503,20:00:00,1,1200
2018-11-01 20:20:00,1,20,20,132.90939839406852,67.6641419034086,20:20:00,1,1220
2018-11-01 20:40:00,1,20,40,80.28565707426297,54.21677488141204,20:40:00,1,1240
2018-11-01 21:00:00,1,21,0,86.51819145398362,76.47547776446376,21:00:00,1,1260
2018-11-01 21:20:00,1,21,20,100.58643623741963,54.02216986378453,21:20:00,1,1280
2018-11-01 21:40:00,1,21,40,109.88077988150214,88.83099789311015,21:40:00,1,1300
2018-11-01 22:00:00,1,22,0,133.64148337171653,86.82795237554191,22:00:00,1,1320
2018-11-01 22:20:00,1,22,20,141.1790901060669,55.91956277329068,22:20:00,1,1340
2018-11-01 22:40:00,1,22,40,106.49414930906852,74.54271614590431,22:40:00,1,1360
2018-11-01 23:00:00,1,23,0,140.44553457410672,78.3447955131424,23:00:00,1,1380
2018-11-01 23:20:00,1,23,20,102.26703222395386,54.51054689408265,23:20:00,1,1400
2018-11-01 23:40:00,1,23,40,138.07031707200693,80.52691368274375,23:40:00,1,1420
2018-11-01 00:00:00,1,0,0,131.8403388480975,163.40706930229612,00:00:00,1,0
2018-11-01 00:20:00,1,0,20,128.66143180880016,182.4166850946821,00:20:00,1,20
2018-11-01 00:40:00,1,0,40,157.9838672230082,177.12826879097582,00:40:00,1,40
2018-11-01 01:00:00,1,1,0,154.74491894762372,177.0205615343229,01:00:00,1,60
2018-11-01 01:20:00,1,1,20,145.17425322202857,170.28572211898427,01:20:00,1,80
2018-11-01 01:40:00,1,1,40,86.33692934233684,161.306233500133,01:40:00,1,100
2018-11-01 02:00:00,1,2,0,157.70472270832147,175.57007397898963,02:00:00,1,120
2018-11-01 02:20:00,1,2,20,92.04378773072384,152.75885569609832,02:20:00,1,140
2018-11-01 02:40:00,1,2,40,94.91482763887927,164.34713115356462,02:40:00,1,160
2018-11-01 03:00:00,1,3,0,150.58752716935703,152.5739950034875,03:00:00,1,180
2018-11-01 03:20:00,1,3,20,147.64763286003245,181.7346317353725,03:20:00,1,200
2018-11-01 03:40:00,1,3,40,152.00311766772614,169.43438782829136,03:40:00,1,220
2018-11-01 04:00:00,1,4,0,90.67568616871652,165.94364405219295,04:00:00,1,240
2018-11-01 04:20:00,1,4,20,127.6260776280666,154.41327889693227,04:20:00,1,260
2018-11-01 04:40:00,1,4,40,88.35193693321801,86.7514997924824,04:40:00,1,280
2018-11-01 05:00:00,1,5,0,99.44723697225662,61.81705113015809,05:00:00,1,300
2018-11-01 05:20:00,1,5,20,153.28490595395064,70.71671056760238,05:20:00,1,320
2018-11-01 05:40:00,1,5,40,139.53124376248127,86.96902617467873,05:40:00,1,340
2018-11-01 06:00:00,1,6,0,144.5960580946409,53.46091762212306,06:00:00,1,360
2018-11-01 06:20:00,1,6,20,110.0561197803852,73.32550566412914,06:20:00,1,380
2018-11-01 06:40:00,1,6,40,151.21482961729612,50.85883825605632,06:40:00,1,400
2018-11-01 07:00:00,1,7,0,127.88766918064591,52.45266678876003,07:00:00,1,420
2018-11-01 07:20:00,1,7,20,148.72830141013,60.496196118302194,07:20:00,1,440
2018-11-01 07:40:00,1,7,40,83.62908148257569,86.54612924908034,07:40:00,1,460
2018-11-01 08:00:00,1,8,0,113.49475177931872,59.15439348393694,08:00:00,1,480
2018-11-01 08:20:00,1,8,20,139.37377082538475,86.1347823168292,08:20:00,1,500
2018-11-01 08:40:00,1,8,40,104.5216263376223,86.92624219265554,08:40:00,1,520
2018-11-01 09:00:00,1,9,0,152.55680056900144,60.938994790632144,09:00:00,1,540
2018-11-01 09:20:00,1,9,20,140.38896796205978,56.19504976107255,09:20:00,1,560
2018-11-01 09:40:00,1,9,40,135.79579769996857,62.50941443441722,09:40:00,1,580
2018-11-01 10:00:00,1,10,0,139.82904911416367,55.70678841865249,10:00:00,1,600
2018-11-01 10:20:00,1,10,20,91.69787531743796,60.136426910820354,10:20:00,1,620
2018-11-01 10:40:00,1,10,40,96.81085932421924,80.24824051838286,10:40:00,1,640
2018-11-01 11:00:00,1,11,0,100.11254271252508,60.56291710797137,11:00:00,1,660
2018-11-01 11:20:00,1,11,20,92.56760281588778,71.09234847495347,11:20:00,1,680
2018-11-01 11:40:00,1,11,40,100.3186503333999,72.55516506446128,11:40:00,1,700