yash patel

yash patel

  • NA
  • 274
  • 19.6k

Not getting value for x-axis while using jquery flot for chart

Sep 8 2021 12:41 PM

This graph is plotted using jquery

 

I am getting api resonse in "function (response) "

this is the function for getting data for graph

var total_data = [], date_data=[];
                    var getRandomData = function () {
                        if (response != null && response.data.length > 0) {
                            for (var i = 0; i < response.data.length; i++) {
                                var total_count = response.data[i].total;
                                var dt = response.data[i].date;
                               
                                total_data.push(total_count);
                                date_data.push(dt);
                               
                            }
                        }
                        
                        var res = [];
                        for (var i = 0; i < response.data.length; ++i)
                            debugger;
                            res.push([date_data[i], total_data[i]])
                        return res;
                    }

 

 var options = {
                        colors: [color.primary._700],
                        series:
                        {
                            lines:
                            {
                                show: true,
                                lineWidth: 0.5,
                                fill: 0.9,
                                fillColor: {
                                    colors: [{
                                        opacity: 0.6
                                    }, {
                                        opacity: 0
                                    }]
                                },
                            },
                            shadowSize: 0 // Drawing is faster without shadows
                        },
                        grid:
                        {
                            borderColor: 'rgba(0,0,0,0.05)',
                            borderWidth: 1,
                            labelMargin: 5
                        },
                        xaxis:
                        {
                            color: '#F0F0F0',
                            tickColor: 'rgba(0,0,0,0.05)',
                            font:
                            {
                                size: 10,
                                color: '#999'
                            }
                        },
                        yaxis:
                        {
                            min: 0,
                            max: 700,
                            color: '#F0F0F0',
                            tickColor: 'rgba(0,0,0,0.05)',
                            font:
                            {
                                size: 10,
                                color: '#999'
                            }
                        }
                    };

                    var plot = $.plot($("#TotalCountChart"), [getRandomData()], options);

 

 

I am not geting values for x-axis 

The response is coming in this format for date"

2021-09-06

"

 

If setting mode:time in x-axis only one date is coming "1970-01-01"

 

How to i resolve it?