score:2
Accepted answer
considering you have two arrays (marketing
and amount
) as such :
var marketing = ['2017-08-05', '2017-08-12'];
var amount = [50, 70];
you can create/populate the annotations
array dynamically based on one of those arrays (marketing/amount) to draw multiple vertical lines, like so :
// populate 'annotations' array dynamically based on 'marketing'
var annotations = marketing.map(function(date, index) {
return {
type: 'line',
id: 'vline' + index,
mode: 'vertical',
scaleid: 'x-axis-0',
value: date,
bordercolor: 'green',
borderwidth: 1,
label: {
enabled: true,
position: "center",
content: amount[index]
}
}
});
see a working example.
Source: stackoverflow.com
Related Query
- ChartJS / Chartjs-plugin-annotation How to draw multiple vertical lines using an array?
- Can't Draw Horizontal Line on Graph Using ChartJS Annotation Plugin and Primevue Chart
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- How to draw horizontal Lines using chart.js 3.x ? Cannot get it working
- How to draw multiple line on y axis for same x axis in chartjs v2?
- How to draw multiple color bar in a bar chart using chart.js
- How to set vertical lines for new day on x-axis in ChartJS v3.x
- How to draw a range label on x axis using chartJS
- How to draw multiple color bars in a bar chart along a Horizontal Line using chart.js
- Chartjs annotations-plugin: Can I add multiple vertical lines to identically named x-axis labels?
- ChartJs How to display horizontal and vertical lines through the datasets points with their values on axes?
- How to run Chart.js samples using source code
- How to draw multiple lines in chart.js
- How do I draw horizontal bars with a label using either ChartJS or D3?
- How to add vertical line in bar chart using chartJs and ng2-charts?
- how to plot multiple time series in chartjs where each time series has different times
- How to Draw Gantt chart using chart js or other libraries
- ChartJS : How to leave just points without lines
- How can I draw dotted line using chartjs?
- How do I draw a vertical line on a horizontal bar chart with ChartJS?
- how to show multiple values in point hover using chart.js
- How to properly use the chartjs datalabels plugin
- How to render a vertical line on hover in chartjs
- Draw two plots using chartjs over one another with transparency
- How to draw Horizontal line on Bar Chart Chartjs
- How to work out Chartjs using TypeScript with Chartjs.definitelyTyped from github
- Want to draw data using chartjs in django
- How to use chart.js script to draw multiple pie Charts
- Multiple stacked bar chart using ChartJs
- How to add background color between two lines in yAxis Chartjs
More Query from same tag
- Chart JS — Conditional horizontal row background colours
- ng-charts not updating labels when chart data is updated at same time
- MongoDB based data is not populating in Chart.js
- Different color for line segments in ChartJS
- Change tooltips title at chart.js?
- How to add links to chart.js (Doughnut Charts)?
- Chart.js v2 formatting time labels
- ChartJs, How can I get different color fills between my two datasets in a line graph?
- How do I make a pie chart showing number of people in an age group with JSON and ChartJS?
- ChartJs chart in typescript: Object is possibly undefined in useEffect
- JavaScript implementation doesnt work (Chart.js)
- why Graph is not showing until i minimize window. (using chart.js )
- How to access specific data values from tooltip - Chart.js
- How to remove grid on chart.js
- Updating chart.js with JSON from Razor page
- Grouping by month with series of epoch timestamps in Chart.js
- Vue.js: How to retrieve data from API for vue chart.js
- Chartjs: display different average line while grouping
- How to add the value for each label to pie legend
- How to fit Doughnut Chart JS into Bootstrap column?
- How can I move a label left, paint it black, or remove it (Chart.JS)?
- ChartJS vertical bar chart - measure percentage of the data in each column based on a specified max
- Is it possible to pot a line chart of date vs time in ChartJS?
- React-Redux and Chart.js props Do not rerender
- Dates not displaying on X Axis using Chart.Js on MVC 5
- Why does x axis not increment 'monthly' chart.js. Also, XAxis not taking title
- How do I place a new line in a label with Chart.js?
- I can not properly re scale <canvas> with width and height attributes
- Chart.js Style bold on 1/one/certain label
- Chat.js, Codeigniter and MySQL. Something wrong on recover data