Documentation

Report Edit

Complex Labels Example

This example shows how to create complex labels for chart axes using the onCreateLabelFormatter callback method.

_Jakaylamouth US_Lake Howard US_North Newell US_New Berta US_Lueilwitzland US_New Rudy US_New Jerrodton US_Lucindatown US_Sierraport US_Tessieside US_East Keven US_Norrisburgh US_Port Margaretta US_Woodrowfurt US_Gretchenfort US_Jan2020AprJulOct_Jan2021AprJulOct
<Svg style="width:600px; height:600px;">
    <Chart offset="20 -20 -40 120" axes={{
      y: {
          type: CategoryAxis,
          vertical: true,
          inverted: true,
          labelLineHeight: 1.3,
          onCreateLabelFormatter: () => (formattedValue, value) => {
              let parts = formattedValue.split(';');
              return [{ text: parts[0], style: { fontWeight: 600 }}, { text: parts[1]}];
          }
      },
      x: {
          type: TimeAxis,
          snapToTicks: 0,
          format: "datetime;MMMyyyy",
          labelLineHeight: 1.3,
          onCreateLabelFormatter: () => (formattedValue, value) => {
              let parts = formattedValue.split(' ');
              let result = [{ text: parts[0] }];
              let color = parts[0] == 'Jan' ? 'red' : null;
              if (parts[0] == 'Jan') result.push({ text: parts[1], style: { fontWeight: 600, color }});
              return result;
          }
      }
  }}>
       <Repeater records-bind="$page.points" recordAlias="$point" sorters-bind="$page.sorters">
          <Bar colorIndex={3}
               style="stroke:none;opacity:0.3"
               x0-bind="$point.start"
               x-expr="{$point.start} + {$point.duration}"
               y-bind="$point.city"
               size={0.5}
          />
       </Repeater>
       <Gridlines/>
    </Chart>
 </Svg>
Copied!Cx Fiddle