Pie chart from a single row

Is it possible to display a pie chart based on a single row in a table? Either directly or via some type of magic?

I’ve got a table which I’m logging some numerical data on a weekly basis. In addition to displaying this using a line chart, I also want to display a pie chart using the data from a single row (i.e. the most recent one).

This is what I have so far:

And what I want is somewhat similar to this, based on the data for the most recent row:

Thank you.

There’s a built-in hidden formula PieChart!
Here’s an example :slight_smile:

I’m sure you can get even fancier with a pack or if you’re feeling adventorous create your own SVG to render in coda

3 Likes

That’s amazing, thank you. But I can’t get the image to render

I’ve tried both Safari and Chrome. It’s the same for me in the demo page you’ve listed

That is really weird, I have no idea why that’s happening.
What if you try to wrap it inside an Image call:

Image(PieChart(List(thisRow.Critical, thisRow.Warning, thisRow.Known, thisRow.OK), labels: List("Critical", "Warning", "Known", "OK"), title: "Services").ToText())
1 Like

That doesn’t work either, alas.

The .ToText() is quite revealing, showing that this is powered by Google Charts. The URL it’s giving me is:

https://chart.googleapis.com/chart?chtt=Services&cht=p&chco=ff5a3d%2C2c8086%2Cf9a014%2Cff7b2b%2C84409c%2Ceb72c9%2C21b6af&chs=200x200&chd=t%3A38%2C4%2C1%2C404&chdl=Critical%7CWarning%7CKnown%7COK

which I’ve tried directly in my browser, resulting in an Error 502. I’m not sure if this is because there’s an error in the URL, or if Google is having some issues.


I wonder if there’s another way to do this? Coda pie charts are expecting the sections of the chart to be different rows. Is there a dynamic way we can create a table populated from another table as multiple rows instead of columns?

Is there a way I can specify which field I want to read from based on a string?

That is, if I have a row with the following fields:

  • Critical
  • Warning
  • Known
  • OK

and access to the name of one of the field as a string i.e. "Known" - is there some way I can reference that field name using that string in a formula?

I’m hoping to build something like this, using the name field to dynamically populate the relevant value from the other table.

I had a look at the documentation, but I can’t see anything obvious.

That’s weird regarding the url.

For the row reference you can write @Critical.Number (gotta select the correct row when writing @Critical).

Or just [Pie chart].Filter(Name=Critical).First().Number

Oh and the Pie chart formula becomes much cleaner with this new transposed table:

PieChart([Pie chart].Number, labels: [Pie chart].Name, title: "Services", is3d: True)
1 Like

Sorry, I don’t think I’ve explained myself very well.

I want to populate the Number column of the Pie chart table from another table. I want to use the Name column in the table as the reference for which field to read from that other table.

Right now I have this as a formula in the Number column:

First(sort([Services Data],false, [Services Data].Date )).Critical

But this means the Critical field is hard-coded. I want to make this dynamnic, using the value from the Name field.

The pseudocode would look something like this:

First(sort([Services Data],false, [Services Data].Date )).columnName(thisRow.Name)

Does that make sense?

Ah gotcha, funny you’re talking to me then, I made a suggestion 10 months ago for new column formulas. So I’m afraid this specific approach is currently not possible without hard-coding :cry:

1 Like

That’s a shame, I’ve voted on the suggestion in any case. Thanks for your help.

1 Like

PS, I’ve noticed the 3D pie chart from Google is working again now. I guess Google have resolved some of their issues.

1 Like

If you’re willing to adjust the format of the Services Data table, You could structure it with Date as the first Column, Type (or whatever) as the second, and Count as the third; Type is a select-list of your four existing columns, and count is the associated number for each type.

For your charts then, you can use date as the horizontal axis and the values are the numbers in Count, then in the Chart Options, segment the data by Type to get your pies and lines. This will also let you add filters to isolate some types from the others if you want to later.

That should work as-is for an additive chart - if you only want the last two weeks, you can do a filter on the charts to only show that amount of time and you should be off to the races.

2 Likes

Thank you for sharing this great example. @Rickard_Abraham

2 Likes

There is also lots you can do with quickchart.io

For example, try this formula:

Image(Format("https://quickchart.io/chart?c={type:'radialGauge', data:{
  datasets:
    [{data:[{1}], 
    backgroundColor:'{3}'}]
  },
  options: {
    domain: [0, {2}],
    centerArea: {
      displayText: true,
      text: '{1}/{2}'
    }
  }
}",
  23, 57, 'green'
))

There is way more you can do with it. They have wonderful interactive Pie Chart Documentation too.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.