I have a chart like this (drawn by google charts) the line is generated by google with option of Linear trendlines
code
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Diameter', 'Age'],
[8, 37], [4, 19.5], [11, 52], [4, 22], [3, 16.5], [6.5, 32.8], [14, 72]]);
var options = {
title: 'Age of sugar maples vs. trunk diameter, in inches',
hAxis: {title: 'Diameter'},
vAxis: {title: 'Age'},
legend: 'none',
trendlines: { 0: {} } // Draw a trendline for data series 0.
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
how to know the equation of this line?
adding the trendline to the legend will reveal the equation...
you can remove the series from the legend, if so desired...
see following working snippet...
EDIT
once the equation has been added to the legend,
you can get the value from the
<text>
element used to draw the legend markerbut need to wait on the
'ready'
event first,to know the chart has finished drawing
also, you will need a way to determine the legend marker
<text>
elementfrom the other labels, such as the chart title
in this example, both the title and the legend marker
have an attribute
text-anchor
with a value of'start'
text-anchor
could change depending the legend'salignment
andposition
the font color (
fill
) is used to separate the title from the legend marker...see following working snippet...