# HubDB Google Charts

**URL:** <https://community.hubspot.com/t/hubdb-google-charts/40904>\
**Category:** CMS Development\
**Tags:** hubdb, javascript\
**Created:** [July 18, 2021, 1:05pm UTC](https://community.hubspot.com/t/hubdb-google-charts/40904 "2021-07-18T13:05:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cives](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cives/32/57633_2.png) [@cives](https://community.hubspot.com/u/cives)\
**Post date:** [July 18, 2021, 1:05pm UTC](https://community.hubspot.com/t/hubdb-google-charts/40904/1 "2021-07-18T13:05:54Z")

</div>

Hi all — I need a little assistance on the google chart below; it’s just about complete, though I’m getting hung up on choice.row\_count.

As I loop through cat in category I need it to also return the number of table rows that have that specific category; ideally rendering something like:

[‘Body Shop’, 12],

[‘Car Dealer’, 71]

etc. etc..

Any thoughts? Thank you.

```lia-code-sample
	<script src="https://www.gstatic.com/charts/loader.js" type="text/javascript">
	</script>
	<script type="text/javascript">
	 google.charts.load("current", {packages:["corechart"]});
	 google.charts.setOnLoadCallback(drawChart);
	 function drawChart() {
	 var data = google.visualization.arrayToDataTable([

	 {% set table_info = hubdb_table_rows(2666166) %}
	 {% set category = [] %} 
	 {% for row in table_info %}

	 {% set option = row.member_category %}
	 {% for choice in option %}
	 {% do category.add(choice) %}

	 {% endfor %}
	 {% endfor %}

	 ['Members', 'Type'],

	 {% for cat in category|unique('name') %}
	 ['{{ cat.name }}', {{ choice.row_count }}],
	 {% endfor %}
	 ]);

	 var options = { 
	 pieHole: 0.4,
	 };

	 var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
	 chart.draw(data, options);
	 }
	</script>

	<div id="donutchart" style="width: 500px; height: 500px;"></div>

```

---

<div class="post-metadata">

**Author:** ![Indra](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/indra/32/98381_2.png) [@Indra](https://community.hubspot.com/u/Indra)\
**Post date:** [July 19, 2021, 8:12am UTC](https://community.hubspot.com/t/hubdb-google-charts/40904/2 "2021-07-19T08:12:00Z")

</div>

@Hi @cives,

When getting table info from a column, you can use the [column info](https://developers.hubspot.com/docs/cms/data/hubdb#getting-column-info) by using .options.

So your code will look like this:

`{% set categories = hubdb_table_column(module.db , 'member_category').options %}`

The only tricky part is that it does not have a build in function to get the amount of items/rows with it. So you have to loop through the object to count the items.

So your code will look something like this:

```lia-code-sample
{% set db = module.db %}
{% set table_info = hubdb_table_rows(db) %}
{% set cat_field = 'member_category' %}
{% set categories = hubdb_table_column(module.db , cat_field).options %}

[
{% for category in categories %}

 {# Setup count for current term #}
 {% set count = {'value': 0} %}
 {# Loop through the table #}
 {% for row in table_info %}
 {# Set counts and add up 1 #}
 {% set counts = count.value|int + 1 %}
 {% for cat in row[cat_field] %}
 {# Check if row category is equal to current category #}
 {% if category.id == cat.id %}
 {# Update counts #}
 {% do count.update({ 'value': counts }) %}
 {% endif %}
 {% endfor %}
 {% endfor %}
 '{{ category.name }}', '{{ count.value }}'{% if !loop.last %},{% endif %}
{% endfor %}
]

```

Did this answered your question? If so, please mark your question as resolved.

---

<div class="post-metadata">

**Author:** ![cives](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cives/32/57633_2.png) [@cives](https://community.hubspot.com/u/cives)\
**Post date:** [July 19, 2021, 9:45pm UTC](https://community.hubspot.com/t/hubdb-google-charts/40904/3 "2021-07-19T21:45:01Z")

</div>

Worked like a charm. Thank you!
