First of all, I would like to make it clear that I did go through the following link posted in stackoverflow :
Resize svg when window is resized in d3.js
Following is the link to jsfiddle and code: https://jsfiddle.net/adityap16/d61gtadm/8/
Code-
var data = [
{"mytime": "2015-12-01T11:10:00.000Z", "value": 64},
{"mytime": "2015-12-01T11:15:00.000Z", "value": 67},
{"mytime": "2015-12-01T11:20:00.000Z", "value": 70},
{"mytime": "2015-12-01T11:25:00.000Z", "value": 64},
{"mytime": "2015-12-01T11:30:00.000Z", "value": 72},
{"mytime": "2015-12-01T11:35:00.000Z", "value": 75},
{"mytime": "2015-12-01T11:40:00.000Z", "value": 71},
{"mytime": "2015-12-01T11:45:00.000Z", "value": 80}
];
var parseDate = d3.time.format("%Y-%m-%dT%H:%M:%S.%LZ").parse;
data.forEach(function(d) {
          d.mytime = parseDate(d.mytime);
        });
//var margin = { top: 30, right: 30, bottom: 40, left:50 },
var margin = { top: 30, right: 30, bottom: 40, left:50 },
height = 200,
width = 800;
var color =  "green";
var xaxis_param = "mytime";
var yaxis_param = "value"
var params1 =  {margin:margin,height:height,width:width, color: color, xaxis_param:xaxis_param, yaxis_param :yaxis_param};
draw_graph(data,params1);
function  draw_graph(data,params){
    //Get the margin 
    var xaxis_param = params.xaxis_param;
    var yaxis_param = params.yaxis_param;
    var color_code = params.color;
    var margin = params.margin;
    var height = params.height - margin.top - margin.bottom,
        width = params.width - margin.left - margin.right;
    var x_extent = d3.extent(data, function(d){
        return d[xaxis_param]});
    var y_extent = d3.extent(data, function(d){
        return d[yaxis_param]});
    var x_scale = d3.time.scale()
        .domain(x_extent)
        .range([0,width]);
    var y_scale = d3.scale.linear()
        .domain([0,y_extent[1]])
        .range([height,0]);
    //Line
    var lineGen = d3.svg.line()
        .x(function (d) {
            return x_scale(d[xaxis_param]);
        })
        .y(function (d) {
            return y_scale(d[yaxis_param]);
        });
    var myChart = d3.select('body').append('svg')
                    .attr('class','my-chart')
                    .style('background', '#E7E0CB')
                    .attr('width', width + margin.left + margin.right)
                    .attr('height', height + margin.top + margin.bottom)
                    .append('g')
                    .attr('transform', 'translate('+ margin.left +', '+ margin.top +')');
            myChart
                    .append('svg:path')
                    .datum(data)
                    .attr('class', 'line')
                    .attr("d",lineGen)
                    .attr('stroke', color_code)
                    .attr('stroke-width', 1)
                    .attr('fill', 'none');
    var legend = myChart.append("g")
          .attr("class", "legend")
          .attr("transform", "translate(" + 5 + "," + (height - 25) + ")")
        legend.append("rect")
          .style("fill", color_code)
          .attr("width", 20)
          .attr("height", 20);
        legend.append("text")
          .text(yaxis_param)
          .attr("x", 25)
          .attr("y", 12);
    var vGuideScale = d3.scale.linear()
        .domain([0,y_extent[1]])
        .range([height, 0])
    var vAxis = d3.svg.axis()
        .scale(vGuideScale)
        .orient('left')
        .ticks(5)
    var hAxis = d3.svg.axis()
        .scale(x_scale)
        .orient('bottom')
        .ticks(d3.time.minute, 5);
  myChart.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(hAxis);
  myChart.append("g")
      .attr("class", "y axis")
      .call(vAxis)
}
The top voted solution talks about defining the class and making it responsive in css file. When I try to define it that way the code returns an "undefined width" error. I think this is because the axis and other elements are calculated according to the variable width. The only working solution I have been able to come up with is:
var screenWidth =  window.innerWidth;
screenWidth = screenWidth - 0.5*screenWidth;
But after this, whenever the window would be resized, I would have to call d3.select(window).on('resize', resize); and put my code in the resize() function. I am quiet new to javascript and d3 so I might be missing something in the solution already posted. Thanks.
 
     
    