score:9
Accepted answer
This can be done outside of the actual graph by pre-parsing you labels to check that they are sequential in date. In the example below i have made use of momentjs as it just makes date manipulation, formatting and parsing so much easier.
then it is just a case of when finding a date that is not followed by a squential date to add it in to the labels and also the graph data.
var graphData = [55, 10, 5],
labels = ["01-11-2014", "04-11-2014", "05-11-2014"];
for (var i = 0; i < labels.length; i++) {
//make sure we are not checking the last date in the labels array
if (i + 1 < labels.length) {
var date1 = moment(labels[i], "DD-MM-YYYY");
var date2 = moment(labels[i + 1], "DD-MM-YYYY");
//if the current date +1 is not the same as it's next neighbor we have to add in a new one
if (!date1.add(1, "days").isSame(date2)) {
//add the label
labels.splice(i + 1, 0, date1.format("DD-MM-YYYY"));
//add the data
graphData.splice(i + 1, 0, 0);
}
}
}
var ctx = document.getElementById("chart").getContext("2d");
var data = {
labels:labels,
datasets: [{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.5)",
strokeColor: "rgba(220,220,220,0.8)",
highlightFill: "rgba(220,220,220,0.75)",
highlightStroke: "rgba(220,220,220,1)",
data: graphData
}]
};
var myLineChart = new Chart(ctx).Line(data);
console.log(labels);
console.log(graphData);
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment.min.js"></script>
<script src="https://raw.githack.com/leighquince/Chart.js/master/Chart.min.js"></script>
<canvas id="chart" width="500px"></canvas>
Source: stackoverflow.com
Related Query
- dump missing date in data for chartjs
- Missing Tooltip for some data points using chartjs
- chartjs - json data for scatter graph, issue with date
- Chartjs random colors for each part of pie chart with data dynamically from database
- Chartjs v2 - format tooltip for multiple data sets (bar and line)
- Chartjs - data format for bar chart with multi-level x-axes
- Dashed line for missing data in Chart.JS (spanGaps style)
- ChartJS bar not showing up for simple data points
- ChartJS bar chart fixed width for dynamic data sets
- Laravel 5.1 format date array for chart.js data
- Chartjs barchart generate data for an array dataset
- How to create a custom tooltip for chartJS graph with data in JSON array in JavaScript?
- Referencing locally declared variable into an array for data for chartjs
- ChartJS have xAxes labels match data source
- ChartJS not showing data for time series bar chart
- How to set min max for x axis depend on data with Chartjs and Spring Boot?
- Transform JSON data for ChartJS
- ChartJS date reformatting for use?
- Sql Server query that returns prices from each shop on each date and adds a 0 if no data is present for the shopId on a particular date
- How to use date in x value for Object[] in chartjs dataset, I am getting an error: 'TS2322: Type 'string' is not assignable to type 'number'.'
- ChartJs different data for Tooltips
- Calling data from outside of Chartjs code
- Chartjs doughnut chart for conditional data
- getting additional value fields from data source for dx.chartjs doughnut chart
- Update data from server for ChartJS graph
- How to chart missing data in chartjs
- ChartJS fails to render horizontal bar chart for timeseries data
- Angular ChartJs does not show Data for multiple Charts
- Use Google Spreadsheet as data source for Chart.js
- using dynamic array in chartJs for label and data
More Query from same tag
- Chart.js animate chart after clicking a button
- chart.js increase value on click
- Chart.js zoom start at zoomed in
- How to change the time format displayed in the chart?
- What are these line-boxes called in Chart.js, and how do I turn them off?
- Drawing line chart in chart.js with json response
- chart.js hide x/y axis, customize
- React-Chart.js legend onClick function
- Getting "undefined" trying to create a function
- Chart.js time scale not showing data
- How can I build a vertical line without going through my dots on my line graph? (charts.js)
- Chart.JS - Couldn't add the margin/spacing between Y-axis labels
- Adding image on the top of bar in chartjs
- Why the bar are not aligned the y axis
- Checkboxes unchecked after cart.js end of update animation
- wrong rendered bar chart Chart.js
- chart.js random weird problems
- Chart.JS multiple plugins do not operate
- Chart.js boxplot: adding additional reference value?
- In Chart.js I want to show dotted gridLines like in below image
- Angular ChartJs colors option not working
- Options beginAtZero doesn't work in angular-chart.js
- How to represent MySQL data in the form of charts
- How to set minimum value to Radar Chart in chart js
- Angular2 Update ng2-charts with labels
- Javascript and chart.js, how to add euro currency to y label
- Chart.js pie tooltip getting cut
- Chart.js v2.6: Add arrows to pie chart output values
- Y-axis scale uneven
- Chartjs change grid line color