Skip to main content
Version: 1.2.0

Column Chart

A column chart is a data visualization where each category is represented by a rectangle, with the height of the rectangle being proportional to the values being plotted. Column charts are also known as vertical bar charts. Idea is to develop column charts in react-vis. React-vis is a charting library that provides chart components. In other words, the chart is composed of multiple sub-components like XYPlot, xAxis, yAxis. The following are the components that are used to develop a column chart.

Live Editor

Usage

import { ColumnChart } from "@k2/rv-viz";

2 . Add data or URL to ColumnChart component.

<ColumnChart data={ColumnChartData} />
// or
<ColumnChart url="server/api/data" />

Examples

Basic ColumnChart With X and Y Axis: Demo

<ColumnChart
barWidth={0.1}
data={[
{
data: [
{
x: "bar-1",
y: 100,
},
{
x: "bar-2",
y: 200,
},
{
x: "bar-3",
y: 300,
},
{
x: "bar-4",
y: 400,
},
{
x: "bar-11",
y: 100,
},
{
x: "bar-12",
y: 200,
},
{
x: "bar-13",
y: 300,
},
{
x: "bar-14",
y: 400,
},
],
name: "series 1",
},
]}
title={<span>Heading</span>}
xAxis={{
style: {
fontSize: "12px",
strokeWidth: 0.6,
},
tickPadding: 15,
tickSizeInner: 0,
tickSizeOuter: 6,
}}
xyPlot={{
yDomain: [0, 400],
}}
yAxis={{
hideLine: true,
style: {
fontSize: "12px",
},
tickPadding: 15,
tickSize: 0,
tickTotal: 2,
}}
/>

Basic ColumnChart with Labels: Demo

<ColumnChart
barWidth={0.1}
data={[
{
data: [
{
x: "Jun 1",
y: 100,
},
{
x: "Jun 2",
y: 200,
},
{
x: "Jun 3",
y: 300,
},
{
x: "Jun 4",
y: 400,
},
{
x: "Jun 5",
y: 100,
},
{
x: "Jun 6",
y: 200,
},
{
x: "Jun 7",
y: 300,
},
{
x: "Jun 8",
y: 400,
},
],
name: "Inside Links",
},
{
data: [
{
x: "Jun 1",
y: 100,
},
{
x: "Jun 2",
y: 200,
},
{
x: "Jun 3",
y: 300,
},
{
x: "Jun 4",
y: 400,
},
{
x: "Jun 5",
y: 100,
},
{
x: "Jun 6",
y: 200,
},
{
x: "Jun 7",
y: 300,
},
{
x: "Jun 8",
y: 400,
},
],
name: "Outside Links",
},
]}
title={<span>Heading</span>}
tooltip={{
component: function noRefCheck() {},
}}
xyPlot={{
stackBy: "y",
}}
/>

Stacked ColumnChart With Legends: Demo

<ColumnChart
barWidth={0.1}
data={[
{
data: [
{
x: "Jun 1",
y: 100,
},
{
x: "Jun 2",
y: 200,
},
{
x: "Jun 3",
y: 300,
},
{
x: "Jun 4",
y: 400,
},
{
x: "Jun 5",
y: 100,
},
{
x: "Jun 6",
y: 200,
},
{
x: "Jun 7",
y: 300,
},
{
x: "Jun 8",
y: 400,
},
],
name: "Inside Links",
},
{
data: [
{
x: "Jun 1",
y: 100,
},
{
x: "Jun 2",
y: 200,
},
{
x: "Jun 3",
y: 300,
},
{
x: "Jun 4",
y: 400,
},
{
x: "Jun 5",
y: 100,
},
{
x: "Jun 6",
y: 200,
},
{
x: "Jun 7",
y: 300,
},
{
x: "Jun 8",
y: 400,
},
],
name: "Outside Links",
},
]}
title={<span>Heading</span>}
xyPlot={{
stackBy: "y",
}}
/>

Grouped ColumnChart With Legends: Demo

<ColumnChart
barWidth={0.2}
data={[
{
data: [
{
x: "Jun 1",
y: 100,
},
{
x: "Jun 2",
y: 200,
},
{
x: "Jun 3",
y: 300,
},
{
x: "Jun 4",
y: 400,
},
{
x: "Jun 5",
y: 100,
},
{
x: "Jun 6",
y: 200,
},
{
x: "Jun 7",
y: 300,
},
{
x: "Jun 8",
y: 400,
},
],
name: "Embedded Links",
},
{
data: [
{
x: "Jun 1",
y: 100,
},
{
x: "Jun 2",
y: 200,
},
{
x: "Jun 3",
y: 300,
},
{
x: "Jun 4",
y: 400,
},
{
x: "Jun 5",
y: 100,
},
{
x: "Jun 6",
y: 200,
},
{
x: "Jun 7",
y: 300,
},
{
x: "Jun 8",
y: 400,
},
],
name: "Inside Links",
},
{
color: "#b177bb",
data: [
{
x: "Jun 1",
y: 100,
},
{
x: "Jun 2",
y: 200,
},
{
x: "Jun 3",
y: 300,
},
{
x: "Jun 4",
y: 400,
},
{
x: "Jun 5",
y: 100,
},
{
x: "Jun 6",
y: 200,
},
{
x: "Jun 7",
y: 300,
},
{
x: "Jun 8",
y: 400,
},
],
name: "Outside Links",
},
]}
title={<span>Heading</span>}
/>

Props

Note: External props are mostly derived from react-vis & K2. All external props are linked. You can click highlighted props to get more details from official sites.

PropertyTypeRequiredDefault valueDescription
dataColumnChartData[]yesData for the chart.
xyPlotXYPlotPropsnoNoneCustomize XYPlot. Inherited from "react-vis".
xAxisboolean | XAxisPropsnotrueEnable or customize XAxis. Inherited from "react-vis".
yAxisboolean | YAxisPropsnotrueEnable or customize YAxis. Inherited from "react-vis".
verticalGridLinesboolean | VerticalGridLinesPropsnofalseEnable or customize VerticalGridLines. Inherited from "react-vis".
horizontalGridLinesboolean | HorizontalGridLinesPropsnofalseEnable or customize HorizontalGridLines. Inherited from "react-vis".
barWidthnumberno0.3Inherited from "react-vis" BarSeries
titlestring | JSX.ElementnoNoneTitle of the chart.
animatebooleannotrueEnable the animation.
colors{[theme-name: e.g "light" or "dark"] : string[] | GradientColor[]no{ dark: ["#5579ae", "#e5c238", "#CF7373", "#85BE50"], light: ["#5579ae", "#e5c238", "#CF7373", "#85BE50"], }Colors of visual in different theme modes
labelboolean | LabelComponentnotrueEnable or customize the labels(Note: Labels appear only in case of single series).
tooltipboolean | TooltipPropsnotrueEnable or customize the tooltip.
legendsboolean | LegendsPropsnotrueEnable or customize the legends.
onClickonClick?: (event: { data: VerticalBarSeriesPoint }) => void;noNoneCallback for column click.
styleCSSPropertiesnoNoneStyles applied to the root element of chart.
classNamestringnoNoneClass applied to the root element of chart.
classesClassesnoNoneClasses of chart.

ColumnChart is wrapped with fetchData HoC, to perform data handling tasks, which adds support for some additional props.

Custom Types

ColumnChartData

Here is the format of the data accepted by ColumnChart.

interface ColumnChartData extends Omit<VerticalBarSeriesProps, "data"> {
name: string;
data: VerticalBarSeriesPoint[];
}

VerticalBarSeriesProps and VerticalBarSeriesPoint are derived from react-vis

LabelComponent

This is a type of custom label component. You can create a custom label component by this.

type LabelComponent =
| boolean
| ((props: { data: VerticalBarSeriesPoint }) => JSX.Element);

VerticalBarSeriesPoint is derived from react-vis

GradientColor

Type of GradientColor object.

type GradientColor = {
name: string,
startingColor: string,
endingColor: string,
startingColorStopOpacity?: number,
endingColorStopOpacity?: number,
x1?: string,
x2?: string,
y1?: string,
y2?: string,
};

Classes

Classes enable customization and styling of chart elements through their classes.

ClassNameTypeRequiredDefault valueDescription
rootstringnoNoneApplied to root element of chart.
headerstringnoNoneApplied to header of chart.
titlestringnoNoneApplied to title of chart.
legendsstringnoNoneApplied to legends of chart.
tooltipstringnoNoneApplied to tooltip of chart.
chartstringnoNoneApplied to svg component of chart.
barSeriesstringnoNoneApplied to bar series of chart.
xAxisstringnoNoneApplied to x axis of chart.
yAxisstringnoNoneApplied to y axis of chart.
labelstringnoNoneApplied to labels of chart.

Please see Class Specificity for correctly defining it.