I'm using the Google Chart Chart column chart.
I would like to insert a vertical line in a given position dynamically.
I have an array that indicates value = > amount. In a fictitious example, it would look something like (5 (note) => 500 (number of people who hit 5)).
Ex:
$arr = array('<=4' => 500, 5 => 500, 6 => 300);
There is a variable x, which will be given a value from 0 to 10, which must be represented in the graph through the vertical line already mentioned, indicating the position among the others.
In the image example, I used $x = 9
and I placed it in their respective position.
Then, finally, the doubts remain:
How to insert the vertical bar?
How do you make it position proportional to the X axis?
Expectedresult:
JS+HTML
google.charts.load("current", {packages: ['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
["Element", "Density", {role: 'annotation'}],
["<=4", 672, "672"],
["5", 648, "648"],
["6", 709, "709"],
["7", 569, "569"],
["8", 459, "459"],
["9", 223, "223"],
["10", 17, "17"],
]);
var view = new google.visualization.DataView(data);
var options = {
title: "Descrição",
width: 1159,
height: 400,
bar: {groupWidth: "95%"},
legend: {position: "none"},
};
var chart = new google.visualization.ColumnChart(document.getElementById("grafico"));
chart.draw(view, options);
}
<div id="grafico" style="width: 900px; height: 300px;"></div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>