score:0
i was looking for an answer to a similar problem, and i ended up with the following hack which isn't necessarily a better hack than yours :-)
link to fiddle: https://jsfiddle.net/hdahle/obc4amfh/
var colors = ['red', 'blue', 'yellow', 'green', 'purple', 'orange']
var votes = [5, 6, 35, 76, 20, 10];
var ctx = document.getelementbyid('mychart');
var mychart = new chart(ctx, {
options: {
responsive: true,
legend: {
display: false
}
},
type: 'line',
data: {
labels: colors,
datasets: [{
label: 'votes',
data: votes,
bordercolor: 'rgba(30,150,60,0.8)',
backgroundcolor: 'rgba(30,150,60,0.3)',
borderwidth: 1,
fill: true,
}]
}
});
function drawhorizontalline(value, color) {
let d = [];
for (let i = 0; i < mychart.data.labels.length; i++) {
d.push(value)
}
mychart.data.datasets.push({
data: d,
pointradius: 0,
type: 'line',
bordercolor: color,
borderwidth: 1,
fill: false,
});
mychart.update();
}
drawhorizontalline(76, 'rgba(175,40,50,0.6)');
drawhorizontalline(44, 'rgba(175,40,50,0.6)');
drawhorizontalline(21, 'rgba(175,40,50,0.6)');
drawhorizontalline(12, 'rgba(175,40,50,0.6)');
drawhorizontalline(3, 'rgba(175,40,50,0.6)');
Source: stackoverflow.com
Related Query
- setting uneven tick stepsize spacing with chart.js
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- what is wrong with my code ? java script chart position
- Trouble with setting background color for Line chart at Chartjs version 3.5.1
- Chart.js - Increase spacing between legend and chart
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- Chartjs random colors for each part of pie chart with data dynamically from database
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- How to prevent first/last bars from being cut off in a chart with time scale
- ChartJS - Draw chart with label by month, data by day
- Horizontal stacked bar chart with chart.js
- line chart with {x, y} point data displays only 2 values
- Vertical stacked bar chart with chart.js
- Display line chart with connected dots using chartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Chart.js - line chart with two yAxis: "TypeError: yScale is undefined"
- How to fix chart Legends width-height with overflow scroll in ChartJS
- How to display Line Chart dataset point labels with Chart.js?
- chart js how to fill legend box with colour
- Chart.js setting maximum bar size of bar chart
- Chart.js Mixed Bar and Line chart with different scales
- chart.js Line chart with different background colors for each section
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- reactive chart with chart.js in meteor
- chartjs: How to plot multi-line chart with irregular intervals
- Problem for display a chart with Chart.js and Angular
- How to display inline values in a stacked bar chart with Chart.js?
- Chart.js - Draw bar chart with multiple labels
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- ChartJS bar chart with legend which corresponds to each bar
More Query from same tag
- Chart js disable popup
- Adding a line break in Chart.js (2.7.2) labels section
- Chartjs: display different average line while grouping
- How to hide the legend display for a specific chart?
- Adding data to Chart.js line graph from array
- How to add an event when clicking a bubble in bubble chart?
- Refreshing scope variable not working with scope function
- Chart js cut the title and the legends
- Having problems displaying multiple charts on a page
- Chart.js : How to fill the area under the line to a certain point?
- dataset not accepted in declaration of scatterChartData for Chartjs
- Artefacts when showing compact vertical bar chart in chart.js
- Display values outside of pie chart in chartjs
- Laravel displaying a chart from another database connection
- Hiding unused axis in ng2-charts
- How do I override the function convertTicksToLabels chartjs
- Chart.js v3.2 Change Radar background shape from Polygonal-Triangle to Circular
- Chart with tool tip values
- Why is my Line Chart not displaying (Chart.JS)?
- How to assign specific colors to data items in a doughnut chart in Angular Chart?
- Adding trendlines to existing chart Chart.js
- how to change size of point in ChartJS
- how to sort tooltip value in Chart.js
- Trying to get _index of clicked bar in ChartJS
- Showing Percentage and Total In stacked Bar Chart of chart.js
- How using charts.js with JSON?
- chartJs: I want to show both of the dataset legends when i hover to one of the points?
- tc-angular-chartjs problems while assigning value to chart-data
- creating a chart.js scatter graph with variables for data
- How to add an extra tick on top of the highest bar in Chart.js v2.9.4 (grace)?