You're viewing the legacy site. Visit cxjs.io/docs for the latest documentation. Legacy site. Visit cxjs.io/docs for new docs.

Documentation

Report Edit

Bar Chart Example

This example shows how to connect grid and chart. Sorting and selection in the grid is applied to the chart too.

South HipolitoNew MelvinmouthConroymouthEast InesfortKurtisfurtStanfordportElroytonPort FedericoAishamouthNew BrooksWest KristianPort Monserrate050100150200250
City
V1
V2
V3
South Hipolito100.04246.73152.39
New Melvinmouth100.04151.93234.57
Conroymouth93.82193.87204.72
East Inesfort96.41242.43158.92
Kurtisfurt96.66152.74233.26
Stanfordport94.50149.81222.29
Elroyton88.83235.09206.61
Port Federico102.42184.27153.73
Aishamouth102.24200.57178.78
New Brooks104.86235.18207.54
West Kristian95.50195.15217.83
Port Monserrate107.51212.77211.48
var legendStyle = "border-width:1px;border-style:solid;display:inline-block;width:20px;height:10px;";
<Svg style="width:600px; height:600px;">
   <Chart offset="20 -20 -40 150" axes={{ y: { type: CategoryAxis, vertical: true, inverted: true }, x: { type: NumericAxis, snapToTicks: 1 } }}>
      <Gridlines/>
      <Repeater records-bind="$page.points" recordAlias="$point" sorters-bind="$page.sorters">
         <Bar colorIndex={0}
              height={0.2}
              offset={-0.2}
              x-bind="$point.v1"
              y-bind="$point.city"
              selection={barSelection}
              tooltip-tpl="{$point.v1:n;0}" />

         <Bar colorIndex={2}
              height={0.2}
              offset={0}
              x-bind="$point.v2"
              y-bind="$point.city"
              selection={barSelection}
              tooltip-tpl="{$point.v2:n;0}" />

         <Bar colorIndex={4}
              height={0.2}
              offset={0.2}
              x-bind="$point.v3"
              y-bind="$point.city"
              selection={barSelection}
              tooltip-tpl="{$point.v3:n;0}" />
      </Repeater>
   </Chart>
</Svg>
<Grid records-bind="$page.points"
      sorters-bind="$page.sorters"
      columns={[
         { header: 'City', field: 'city', sortable: true },
         { field: 'v1', format: 'n;2', align: "right", sortable: true,
            header: {
               items: <cx>
                  <div preserveWhitespace>
                     V1
                     <div class="cxs-color-0" style={legendStyle}></div>
                  </div>
               </cx>
            }
         },
         { field: 'v2', format: 'n;2', align: "right", sortable: true,
            header: {
               items: <cx>
                  <div preserveWhitespace>
                      V2
                      <div class="cxs-color-2" style={legendStyle}></div>
                  </div>
               </cx>
            }
         },
         { field: 'v3', format: 'n;2', align: "right", sortable: true,
            header: {
            items: <cx>
               <div preserveWhitespace>
                   V3
                   <div class="cxs-color-4" style={legendStyle}></div>
               </div>
            </cx>
            }
         }
      ]}
      selection={{type: PropertySelection, keyField: 'id', bind: '$page.selection' }}/>
Copied!Cx Fiddle