Numeric axis in React Chart component
19 Sep 202424 minutes to read
You can use numeric axis to represent numeric values of data in chart. By default, the valueType
of an axis is Double
.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Double', title: 'Overs' };
const primaryyAxis = { title: 'Runs' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Double', title: 'Overs' };
const primaryyAxis: AxisModel = { title: 'Runs' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
Range
Range for an axis, will be calculated automatically based on the provided data, you can also customize the range of the axis using minimum
, maximum
and interval
property of the axis.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Double', title: 'Overs', minimum: 1, maximum: 20, interval: 5 };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Double', title: 'Overs', minimum: 1, maximum: 20, interval: 5 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
Range Padding
Padding can be applied to the minimum and maximum extremes of the axis range by using the rangePadding
property. Numeric axis supports following types of padding.
- None
- Round
- Additional
- Normal
- Auto
Numeric - None
When the rangePadding
is set to None
, minimum and maximum of an axis is based on the data.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Double', title: 'Overs', rangePadding: 'None' };
const primaryyAxis = { title: 'Runs' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Double', title: 'Overs', rangePadding: 'None' };
const primaryyAxis: AxisModel = { title: 'Runs' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
Numeric - Round
When the rangePadding
is set to Round
, minimum and maximum will be rounded to the nearest possible value divisible by interval. For example, when the minimum is 3.5 and the interval is 1, then the minimum will be rounded to 3.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Double', title: 'Overs', rangePadding: 'Round' };
const primaryyAxis = { title: 'Runs' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Double', title: 'Overs', rangePadding: 'Round' };
const primaryyAxis: AxisModel = { title: 'Runs' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
Numeric - Additional
When the rangePadding
is set to Additional
, interval of an axis will be padded to the minimum and maximum of the axis.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Double', title: 'Overs', rangePadding: 'Additional' };
const primaryyAxis = { title: 'Runs' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Double', title: 'Overs', rangePadding: 'Additional' };
const primaryyAxis: AxisModel = { title: 'Runs' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
Numeric - Normal
When the rangePadding
is set to Normal
, padding is applied to the axis based on default range calculation.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Double', title: 'Overs', rangePadding: 'Normal' };
const primaryyAxis = { title: 'Runs' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Double', title: 'Overs', rangePadding: 'Normal' };
const primaryyAxis: AxisModel = { title: 'Runs' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
Numeric - Auto
When the rangePadding
is set to Auto
,horizontal numeric axis takes None as padding calculation, while the vertical numeric axis takes Normal as padding calculation.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Double', title: 'Overs', rangePadding: 'Auto' };
const primaryyAxis = { title: 'Runs' };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Double', title: 'Overs', rangePadding: 'Auto' };
const primaryyAxis: AxisModel = { title: 'Runs' };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
Label Format
Numeric Label Format
Numeric labels can be formatted by using the labelFormat
property. Numeric labels supports all globalize format.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis = { title: 'Runs', labelFormat: 'c' };
return <ChartComponent id='charts' primaryYAxis={primaryxAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Runs', labelFormat: 'c' };
return <ChartComponent id='charts'
primaryYAxis={primaryxAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Area'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
The following table describes the result of applying some commonly used label formats on numeric values.
Label Value | Label Format property value | Result | Description |
1000 | n1 | 1000.0 | The Number is rounded to 1 decimal place |
1000 | n2 | 1000.00 | The Number is rounded to 2 decimal place |
1000 | n3 | 1000.000 | The Number is rounded to 3 decimal place |
0.01 | p1 | 1.0% | The Number is converted to percentage with 1 decimal place |
0.01 | p2 | 1.00% | The Number is converted to percentage with 2 decimal place |
0.01 | p3 | 1.000% | The Number is converted to percentage with 3 decimal place |
1000 | c1 | $1000.0 | The Currency symbol is appended to number and number is rounded to 1 decimal place |
1000 | c2 | $1000.00 | The Currency symbol is appended to number and number is rounded to 2 decimal place |
GroupingSeparator
To separate groups of thousands, use useGroupingSeparator
property in chart.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { groupingData } from './datasource';
function App() {
const primaryyAxis = { title: 'Runs' };
return <ChartComponent id='charts' primaryYAxis={primaryyAxis} title='England - Sales Rate' useGroupingSeparator={true}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={groupingData} xName='x' yName='y' name='England' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection, AxisModel }
from'@syncfusion/ej2-react-charts';
import { groupingData } from './datasource';
function App() {
const primaryyAxis: AxisModel = { title: 'Runs' };
return <ChartComponent id='charts'
primaryYAxis={primaryyAxis}
title='England - Sales Rate' useGroupingSeparator={true}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={groupingData} xName='x' yName='y' name='England' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let groupingData = [
{ x: 10, y: 7000 }, { x: 20, y: 1000 },
{ x: 30, y: 12000 }, { x: 40, y: 14000 },
{ x: 50, y: 11000 }, { x: 60, y: 5000 },
{ x: 70, y: 7300 }, { x: 80, y: 9000 },
{ x: 90, y: 12000 }, { x: 100, y: 14000 },
{ x: 110, y: 11000 }, { x: 120, y: 5000 }
];
export let groupingData: Object[] = [
{ x: 10, y: 7000 }, { x: 20, y: 1000 },
{ x: 30, y: 12000 }, { x: 40, y: 14000 },
{ x: 50, y: 11000 }, { x: 60, y: 5000 },
{ x: 70, y: 7300 }, { x: 80, y: 9000 },
{ x: 90, y: 12000 }, { x: 100, y: 14000 },
{ x: 110, y: 11000 }, { x: 120, y: 5000 }
];
Custom Label Format
Axis also supports custom label format using placeholder like {value}°C, in which the value represent the axis label e.g 20°C.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, AreaSeries } from '@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryyAxis = { labelFormat: '${value}K' };
return <ChartComponent id='charts' primaryYAxis={primaryyAxis} title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
;
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
import * as React from "react";
import * as ReactDOM from "react-dom";
import { AxisModel, ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject,
ColumnSeries, Legend, Category, Tooltip, DataLabel, Zoom, Crosshair, AreaSeries, Selection}
from'@syncfusion/ej2-react-charts';
import { numericData } from './datasource';
function App() {
const primaryyAxis: AxisModel = { labelFormat: '${value}K' };
return <ChartComponent id='charts'
primaryYAxis={primaryyAxis}
title='England - Run Rate'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, AreaSeries, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={numericData} xName='x' yName='y' name='England' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let numericData = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];
export let numericData: Object[] = [
{ x: 1, y: 7 }, { x: 2, y: 1 },
{ x: 3, y: 1 }, { x: 4, y: 14 },
{ x: 5, y: 1 }, { x: 6, y: 10 },
{ x: 7, y: 8 }, { x: 8, y: 6 },
{ x: 9, y: 10 }, { x: 10, y: 10 },
{ x: 11, y: 16 }, { x: 12, y: 6 },
{ x: 13, y: 14 }, { x: 14, y: 7 },
{ x: 15, y: 5 }, { x: 16, y: 2 },
{ x: 17, y: 14 }, { x: 18, y: 7 },
{ x: 19, y: 7 }, { x: 20, y: 10 }
];