score:2
i am not using x/y formatted datasets, so i kept looking. i ended up finding that inserting 'null' values solved my problem--the arrays can then be the same length, and not have drops to zero polluting the shapes.
however, note that this seems to not work with log scales on line graphs. luckily, the only graphs i use uneven-length datasets on is probably best presented in linear form, but it is irritating.
note also that you may want to utilize the { spangaps: false }
option.
score:4
for those facing the same issue and future reference. here is the working code for my case:
<html>
<head>
<script type='text/javascript' src='./momentjs-with-locales.js'></script>
<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.7.2/chart.min.js'></script>
</head>
<body>
<div style="width: 900px; height: 500px">
<canvas id="chart1"></canvas>
</div>
<script>
let chart1 = new chart(document.getelementbyid("chart1"), {
type: 'line',
data: {
labels: ["2018-04-21t16:00:00", "2018-04-21t18:00:00", "2018-04-21t20:00:00", "2018-04-23t12:00:00", "2018-04-23t13:00:00"],
datasets: [
{
fill: false,
label: 'page view',
bordercolor: "hsl(226.15793242887034,78.48665583019744%,62.177112879909686%)",
data: [
{
labels: ["2018-04-21t16:00:00", "2018-04-21t18:00:00", "2018-04-21t20:00:00", "2018-04-23t12:00:00", "2018-04-23t13:00:00"],
},
{
x: new date('2018-04-21t16:00:00'),
y: 7
},
{
x: new date("2018-04-21t18:00:00"),
y: 3
},
{
x: new date("2018-04-21t20:00:00"),
y: 11
},
{
x: new date("2018-04-23t12:00:00"),
y: 2
},
{
x: new date("2018-04-23t13:00:00"),
y: 3
}
],
},
//dataset 2
{
fill: false,
label: 'view content',
bordercolor: "hsl(232.84952363040048,93.45575469963681%,28.844243872178236%)",
data: [
{
labels: ["2018-04-21t17:00:00", "2018-04-21t20:00:00", "2018-04-23t12:00:00", "2018-04-23t13:00:00"],
},
{
x: new date("2018-04-21t17:00:00"),
y: 1
},
{
x: new date("2018-04-21t20:00:00"),
y: 6
},
{
x: new date("2018-04-23t12:00:00"),
y: 1
},
{
x: new date("2018-04-23t13:00:00"),
y: 2
}
],
},
],
},
options: {
animation: {
duration: 0
},
title: {
display: false,
text: ''
},
legend: {
labels: {
uselinestyle: true
},
position: 'bottom',
},
scales: {
xaxes: [
{
type:'time',
distribution: 'series',
time: {
unit: 'day',
displayformat: {
day: 'dd/mm/yyyy'
}
},
}
],
yaxes: [
{
ticks: {
beginatzero: true,
},
}
]
}
}
});
</script>
</body>
</html>
Source: stackoverflow.com
Related Query
- ChartJS - Line Chart with different size datasets
- Display line chart with connected dots using chartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chart.js Mixed Bar and Line chart with different scales
- chart.js Line chart with different background colors for each section
- ChartJS - Line chart issue with only 1 point
- ChartJs line chart - display permanent icon above some data points with text on hover
- ChartJS - how to display line chart with single element as a line? (not as a dot)
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Gradient line chart with ChartJS
- Adding line over stacked line chart with ChartJS
- Updating chart.js chart with dataset of different size
- ChartJS update chart with multiple datasets
- ChartJs - Round borders on a doughnut chart with multiple datasets
- How to reduce the number of points shown on line chartjs chart with a large dataset?
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- React chart2js Line chart with multiple datasets overlapping
- Vertical Line chart with ChartJS
- Real-time line chart with ChartJS using Ajax data
- How do I display two datasets on a single chart with chartjs
- chartjs line graph points with different color
- Plot Multiple Line Chart in Ionic 3 with ChartJS
- drawing line chart with chartjs
- Angular-Chart-JS - Line chart with different fill colors according to points' range
- chartjs display data in one bar line with 3 different data sets in 3 different colors
- 2 Line Chart with different labels | Chart.js
- Two data sets with different time instances on the same ChartJs chart
- Trouble with setting background color for Line chart at Chartjs version 3.5.1
- Draw stacked horizontal bar chart with Average line using ChartJS
- How to show area chart with timeseries configuration with different datasets in Chart.js v3?
More Query from same tag
- chart.js php live update
- Chart js - Polar Scatter Chart
- Chartjs.org Chart only displaying in one page
- displaying the output on chart.js using Django and HTML
- Polar Area onclick event
- Searchable label text Chartjs
- How to mutate VueJS prop?
- How to show scale labels and set min/max for yAxes?
- Chart.js margins
- Error ReferenceError: CanvasGradient is not defined
- Highest (green) and Lowest (red) coordinates plot using Chart.Js
- dyamically constructing javascript object
- Can't Draw Horizontal Line on Graph Using ChartJS Annotation Plugin and Primevue Chart
- Get hash value Rails / Chart JS / Google Chart
- Chartjs to show more set of data of click of a button
- How to draw Horizontal line on Bar Chart Chartjs
- Call ChartJS details in main Javascript file
- ChartJS and Laravel5
- Chart.js tooltip yAlign
- Angular 2 Chart.js and NG2-Charts Not Binding Data Objects After Updates To Project
- Combo Bar Line Chart with Chart.js
- Chartjs: Align first tick in first index of axis
- Get Array with json without _chartjs: {…}, push: ƒ, pop: ƒ, shift: ƒ, splice: ƒ, …]
- Issue loading chart.js zoom plugin with require.js
- How can I skip data/labels in a period of time in Chartjs?
- ChartJS rotate label value vertical
- Chart.js canvas resize
- Ionic not return data from variable
- Chartjs and Polymer 1.7.0
- Chart.js modal window