score:0
Chartjs provides the stepped line chart with the stepped
property for various charts. For example, in the HTML document, add the canvas and with the id:
[html]
<canvas id="myChart" width="400" height="400"></canvas>
<script src="index.js"></script>
[index.js]
const ctx = document.getElementById('myChart').getContext('2d');
const data = {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [5, 4, 3, 6, 2, 3],
borderColor: '#FF0000',
borderWidth: 2,
stepped: 'after',
}]
}
const myChart = new Chart(ctx, {
type: 'line',
data: data,
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
The stepped
could be any of false
, true
, before
, after
, middle
. Please see the docs for more information.
score:2
You can use a d3.svg.line
and set the line.interpolate
to either step-before
or step-after
.
Here is the documentation:
https://github.com/mbostock/d3/wiki/SVG-Shapes#line_interpolate
Here is an example:
score:11
@Baz's answer is perfect for D3 version 3, but for anyone struggling to find similar resources for version 4 (the API changed pretty dramatically)..
The process now is to use d3.curveStepAfter
instead.
An alternative approach is using a line and manually setting the interpolator, eg, d3.line().curve(d3.curveStepAfter)
score:15
Nobody seem to have answered this, but you can do that with chart.js by setting steppedLine: true in the dataset configuration.
var config = {
type: 'line',
data: {
datasets: [{
label: "My dataset",
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()],
steppedLine: true,
}
}
Source: stackoverflow.com
Related Query
- How can I make a stepline or stepped chart in chart.js or D3?
- How can I make two of my lines in Chart JS thicker
- How can I make line on chart thinner?
- How can I make streaming chart with react?
- how can I make selected data is highlighted on chart js?
- How can I make lines fully connected in a multi-line chart even when one dataset is more sparse than another?
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How can I remove extra whitespace from the bottom of a line chart in chart.js?
- how to make a chart.js bar chart scrollable
- Chart js: how can I align the legend and the title
- how to programmatically make a line chart point active/highlighted
- How can I display the xAxes and yAxes data in the tooltip, Chart JS?
- How can I trigger the hover mode from outside the chart with charts.js 2?
- How to make Chart JS responsive?
- How to make bar chart animation where all bars grow at the same speed?
- How can I add some text in the middle of a half doughnut chart in Chart.JS?
- How to make a chart scroll horizontally (when using Chart.js)
- How can I rotate a pie chart in charts.js?
- How to make a chart with an associative array with chart.js?
- How can I achieve displaying data points on chart but Dotted? Chart.js V3.7.0
- Chart is too big. How can I reduce size for the chart in vue js?
- ChartJS: how to make a bar chart with a horizontal guideline:
- How to make aspecific API call from within a Line Chart class in ReactJS using react-chartjs-2?
- how can i modify scale labels in angular chart js?
- I have 10 points inn x-axis, ranging [-25,-20,,-15,-10,0,10,20,30,40,50]. But I want my line chart to start from -15 of x-axis. How we can achieve?
- How can I style scale numbers in a Polar Area chart (chart.js)
- How can I have different values for the chart and the tooltip in chart.js?
- using react-chartjs-2 , How can I save my chart as png using a download button
- How can I add a euro sign (€) to all tooltips in my chart js line chart
More Query from same tag
- getElementById on element from parent component returns null, when called in ngAfterViewInit() of child component
- jquery - How to update line chart.js with multiple datasets
- Change chart.js options based on window width
- One common component for Chart.js to use with different y-axis With React.js
- In Chart.js set chart title, name of x axis and y axis?
- Bar chart with vertical lines in each bar
- ChartJS horizontal label are 1-2px clipped
- In chartjs, add link text on tooltip
- how to change Y axis value dynamically based on user input in Chartjs for Line chart?
- How to add text inside the doughnut chart using Chart.js version 3.2.1
- How to disable canvas elements from hijacking mouse wheel when scrolling through a page?
- how to remove duplicate data set labels in chartjs
- How do I change pointBackgroundColor in Line segment on ChartJS?
- Why chart.js on meteor.js rebuilds itself instead of interpolate new point?
- Why my ajax function does not work on yii2
- Ionic not return data from variable
- Chart.js using json data from MySQL
- Chart JS not rendering on iOS devices
- How to invert scale display on radar chart (chart.js)
- I need to build an array of arrays, having trouble conceptualizing
- Chart.js will not render using vue.js until window resizes
- Chart in Ionic Framework doesn't show up
- Chart.js bar chart: show tooltip on label hover
- Filter a legend Item with Chartjs.org V2.7
- Is there a way to highlight a line on a line graph with hover?
- Chartjs - how to change the notation of doughnut chart
- Angular Dynamic Chart Generate
- ChartJS horizontal chart display legend on each bar
- Chartjs: Need help on drawing a vertical line when hovering cursor
- Struggling with dynamic data