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

Column Chart Example

This example shows how a chart and a grid can be in sync using the same data. Handles on the chart can be used to tweak chart values and changes are automatically reflected in the grid.

JanFebMarAprMayJunJulAugSepOctNovDec0501001502002501052499217981224801687713664144631205718068187641986917172201
MonthV1V2Delta
Jan104.97249.38144.41
Feb91.82178.6886.86
Mar80.54223.87143.33
Apr80.23167.9287.69
May76.93135.6558.72
Jun64.05144.3480.29
Jul63.39119.7756.38
Aug56.54180.00123.46
Sep67.60186.81119.21
Oct63.55198.23134.68
Nov69.15170.54101.39
Dec72.50201.25128.76
<Svg style="width:600px; height:400px;">
   <Chart offset="20 -20 -40 40" 
          axes={{ 
              x: { type: CategoryAxis }, 
              y: { type: NumericAxis, vertical: true, snapToTicks: 0 } 
           }}>
      <Gridlines/>
      <Repeater records-bind="$page.points" recordAlias="$point">
         <Column colorIndex-expr="{$index}"
                 width={0.5}
                 offset={0}
                 x-bind="$point.x"
                 y-bind="$point.v1"
                 tooltip-tpl="{$point.x} {$point.v1:n}"
                 selection={columnSelection} />

         <Column colorIndex-expr="{$index}+2"
                 width={0.5}
                 offset={0}
                 x-bind="$point.x"
                 y0-bind="$point.v1"
                 y-bind="$point.v2"
                 tooltip="X2"
                 selection={columnSelection} />

         <Marker x-bind="$point.x"
                 y-bind="$point.v1"
                 xOffset={0}
                 size={10}
                 colorIndex-expr="{$index}"
                 style="cursor:move;"
                 draggableY>
            <Rectangle anchors="0 1 0 0"
                       offset="-30 10 -10 -10"
                       style="fill:rgba(255, 255, 255, 0.8);stroke:#ccc">
               <Text tpl="{$point.v1:n;0}" ta="middle" dy="0.4em" />
            </Rectangle>
         </Marker>
         <Marker x-bind="$point.x"
                 y-bind="$point.v2"
                 xOffset={0}
                 size={10}
                 colorIndex-expr="{$index}+2"
                 style="cursor:move;"
                 draggableY >
            <Rectangle anchors="0 1 0 0"
                       offset="-30 10 -10 -10"
                       style="fill:rgba(255, 255, 255, 0.8);stroke:#ccc">
               <Text tpl="{$point.v2:n;0}" ta="middle" dy="0.4em" />
            </Rectangle>
         </Marker>
      </Repeater>
   </Chart>
</Svg>
<Grid records-bind="$page.points"
      columns={[
         { header: 'Month', field: 'x' },
         { header: 'V1', field: 'v1', format: 'n;2', align: "right" },
         { header: 'V2', field: 'v2', format: 'n;2', align: "right" },
         { header: 'Delta', value: { expr: "{$record.v2}-{$record.v1}" }, format: 'n;2', align: "right" },
      ]}
      selection={{type: KeySelection, keyField: 'x', bind: '$page.selection' }}/>
Copied!Cx Fiddle