Annotation text Alignment for NEGATIVE values?

21 views
Skip to first unread message

Андрей Малютин

unread,
Apr 29, 2020, 3:21:43 PM4/29/20
to Google Visualization API
Please, someone help me))
How could i place the annotation text to the bottom of the bar, if the value is negative?


Code:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
       <div id="columnchart_values" style="width: 500px; height: 300px;"></div>
<script type="text/javascript">
    google.charts.load("current", {packages:['corechart']});
    google.charts.setOnLoadCallback(drawChart);
    function drawChart() {
      var data = google.visualization.arrayToDataTable([
        ["Element", "Density", { role: "style" } ],
        ["Copper", 8.94, "#b87333"],
        ["Silver", -10.49, "silver"],
        ["Gold", 19.30, "gold"],
        ["Platinum", 21.45, "color: #e5e4e2"]
      ]);

      var view = new google.visualization.DataView(data);
      view.setColumns([0, 1,
                       { calc: "stringify",
                         sourceColumn: 1,
                         type: "string",
                         role: "annotation" },
                       2]);

      var options = {
        title: "Density of Precious Metals, in g/cm^3",
        width: 600,
        height: 400,
        bar: {groupWidth: "95%"},
        legend: { position: "none" },
        
      };
      var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
      chart.draw(view, options);
  }
</script>
2020-04-29_22-05-07.png

Daniel LaLiberte

unread,
Apr 29, 2020, 3:30:43 PM4/29/20
to Google Visualization API
The annotation placement is unfortunately buggy.  The only workaround I can suggest at this time is to stack another series on your series with all zero values, and do the annotations for that new series.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/0d579019-2556-4d91-b893-1fecf53fa6db%40googlegroups.com.


--

Андрей Малютин

unread,
Apr 29, 2020, 3:47:38 PM4/29/20
to Google Visualization API
Thank you, Daniel))) I hope that onetime googgle will fix it))
Reply all
Reply to author
Forward
0 new messages