Summing a cedar chart with custom JSON

170
0
11-27-2018 08:42 AM
KevinHibma
Esri Contributor

Hi,

I'm trying to display a chart in the hub, using the JSON option on the chart card. I'm really close to achieving what I want, I just can't figure out the last bit. I'm trying to plot election candidate results in a bar chart. Each candidate is represented as a column and their votes are field values by precinct. I simply want to sum their total votes and plot them against each other. I think it's my data table making things tricky. If the table was pivot'd I think it'd be easier to do this.

Right now I'm having 2 problems - 

1) In my series-category, I get "undefined" for each candidate. The field property is looking to get a value from the field. But the field name itself is the candidate name. 

2) My candidates get stacked in the bar chart. I think this is how I'm using the series value, but I can't come up with another way to display more than 1 candidate than adding entries to the list like I've done.

{
  "type": "bar-horizontal",
  "datasets": [
    {
      "url": "https://services.arcgis.com/G6F8XLCl5KtAlZ2G/arcgis/rest/services/Ottawa_2018_Election_Results/Featu...",
      "name": "Watson",
      "query": {
        "orderByFields": "Number_of_SUM DESC", 
        "outStatistics": [
          {
            "statisticType": "sum",
            "onStatisticField": "Jim_Watson",
            "outStatisticFieldName": "Number_of_SUM"
          }
        ]
      }
    },
         {
      "url": "https://services.arcgis.com/G6F8XLCl5KtAlZ2G/arcgis/rest/services/Ottawa_2018_Election_Results/Featu...",
      "name": "Doucet",
      "query": {
        "orderByFields": "Number_of_SUM DESC", 
        "outStatistics": [
          {
            "statisticType": "sum",
            "onStatisticField": "Clive_Doucet",
            "outStatisticFieldName": "Number_of_SUM"
          }
        ]
      }
    }
  ],
  "series": [
   {
      "category": {"field": "Jim_Watson", "label": "Candidates"},
      "value": {"field": "Number_of_SUM", "label": "Watson"},
      "source": "Watson"
    },
        {
      "category": {"field": "Clive_Doucet", "label": "Candidates"},
      "value": {"field": "Number_of_SUM", "label": "Doucet"},
      "source": "Doucet"
    }
  ],
  "overrides": {
    "categoryAxis": {
      "labelRotation": -45
    }
  }
}
Tags (3)
0 Kudos
0 Replies