Axis customization in React Chart component
19 Sep 202424 minutes to read
Axis Crossing
An axis can be positioned in the chart area using crossesAt
and crossesInAxis
properties. The crossesAt
property specifies the values (datetime, numeric, or logarithmic) at which the axis line has to be intersected with the vertical axis or vice-versa, and the crossesInAxis
property specifies the axis name with which the axis line has to be crossed.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel } from '@syncfusion/ej2-react-charts';
import { stripData } from './datasource';
function App() {
const primaryxAxis = { crossesAt: 15 };
const primaryyAxis = { crossesAt: 5 };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={stripData} xName='x' yName='y' 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, LineSeries, Selection } from '@syncfusion/ej2-react-charts';
import { stripData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { crossesAt: 15 };
const primaryyAxis: AxisModel = { crossesAt: 5 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={stripData} xName='x' yName='y' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let stripData = [
{ x: 1, y: 20 },
{ x: 2, y: 22 },
{ x: 3, y: 0 },
{ x: 4, y: 12 },
{ x: 5, y: 5 },
{ x: 6, y: 15 },
{ x: 7, y: 6 },
{ x: 8, y: 12 },
{ x: 9, y: 34 },
{ x: 10, y: 7 }
];
export let stripData: Object[] = [
{ x: 1, y: 20 },
{ x: 2, y: 22 },
{ x: 3, y: 0 },
{ x: 4, y: 12 },
{ x: 5, y: 5 },
{ x: 6, y: 15 },
{ x: 7, y: 6 },
{ x: 8, y: 12 },
{ x: 9, y: 34 },
{ x: 10, y: 7 }
];
Title
You can add a title to the axis using title
property to provide quick information to the user about the data plotted in the axis. Title style can be customized using titleStyle
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 } from '@syncfusion/ej2-react-charts';
import { categoryData } from './datasource';
function App() {
const primaryxAxis = {
valueType: 'Category', title: 'Countries', titleStyle: {
size: '16px', color: 'blue', fontFamily: 'Segoe UI', fontWeight: 'bold'
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={categoryData} xName='country' yName='gold' 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, LineSeries, Selection } from '@syncfusion/ej2-react-charts';
import { categoryData } from './datasource';
function App() {
const primaryxAxis: AxisModel = {
valueType: 'Category', title: 'Countries', titleStyle: {
size: '16px', color: 'blue', fontFamily: 'Segoe UI', fontWeight: 'bold'
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={categoryData} xName='country' yName='gold' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let categoryData = [
{ country: "Russia", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "United States", gold: 30, silver: 25, bronze: 27 }
];
export let categoryData: Object[] = [
{ country: "Russia", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "United States", gold: 30, silver: 25, bronze: 27 }
];
Title Rotation
By using the titleRotation
property, you can rotate the axis title from 0 to 360 degree.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel } from '@syncfusion/ej2-react-charts';
import { categoryData } from './datasource';
class App extends React.Component {
primaryxAxis = {
valueType: 'Category', title: 'Countries', titleRotation: 90, titleStyle: {
size: '16px', color: 'blue', fontFamily: 'Segoe UI', fontWeight: 'bold'
}
};
render() {
return <ChartComponent id='charts' primaryXAxis={this.primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={categoryData} xName='country' yName='gold' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>;
}
}
;
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, LineSeries, Selection } from '@syncfusion/ej2-react-charts';
import { categoryData } from './datasource';
class App extends React.Component<{}, {}> {
public primaryxAxis: AxisModel = {
valueType: 'Category', title: 'Countries', titleRotation: 90, titleStyle: {
size: '16px', color: 'blue', fontFamily: 'Segoe UI', fontWeight: 'bold'
}
};
render() {
return <ChartComponent id='charts'
primaryXAxis={this.primaryxAxis}>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={categoryData} xName='country' yName='gold' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
}
};
ReactDOM.render(<App />, document.getElementById("charts"));
export let categoryData = [
{ country: "Russia", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "United States", gold: 30, silver: 25, bronze: 27 }
];
export let categoryData: Object[] = [
{ country: "Russia", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "United States", gold: 30, silver: 25, bronze: 27 }
];
Tick Lines Customization
You can customize the width
, and color
of the minor and major tick lines, using majorTickLines
and minorTickLines
properties in the axis.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel } from '@syncfusion/ej2-react-charts';
import { categoryData } from './datasource';
function App() {
const primaryxAxis = {
valueType: 'Category',
majorTickLines: {
color: 'blue',
width: 5
},
minorTickLines: {
color: 'red',
width: 0
}
};
const primaryyAxis = {
title: 'Temperature (Fahrenheit)',
majorTickLines: {
color: 'blue',
width: 5
},
minorTickLines: {
color: 'red',
width: 0
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Temperature flow over months'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={categoryData} xName='country' yName='gold' name='Sales' 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, LineSeries, Selection } from '@syncfusion/ej2-react-charts';
import { categoryData } from './datasource';
function App() {
const primaryxAxis: AxisModel = {
valueType: 'Category',
majorTickLines: {
color: 'blue',
width: 5
},
minorTickLines: {
color: 'red',
width: 0
}
};
const primaryyAxis: AxisModel = {
title: 'Temperature (Fahrenheit)',
majorTickLines: {
color: 'blue',
width: 5
},
minorTickLines: {
color: 'red',
width: 0
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Temperature flow over months'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={categoryData} xName='country' yName='gold' name='Sales' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let categoryData = [
{ country: "Russia", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "United States", gold: 30, silver: 25, bronze: 27 }
];
export let categoryData: Object[] = [
{ country: "Russia", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "United States", gold: 30, silver: 25, bronze: 27 }
];
Grid Lines Customization
You can customize the width
, color
and dashArray
of the minor and major grid lines using majorGridLines
and minorGridLines
properties in the axis.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel } from '@syncfusion/ej2-react-charts';
import { categoryData } from './datasource';
function App() {
const primaryxAxis = {
valueType: 'Category',
majorGridLines: {
color: 'blue',
width: 1
},
minorGridLines: {
color: 'red',
width: 0
}
};
const primaryyAxis = {
title: 'Temperature (Fahrenheit)',
majorGridLines: {
color: 'blue',
width: 1
},
minorGridLines: {
color: 'red',
width: 0
}
};
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Temperature flow over months'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={categoryData} xName='country' yName='gold' name='Sales' 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, LineSeries, Selection } from '@syncfusion/ej2-react-charts';
import { categoryData } from './datasource';
function App() {
const primaryxAxis: AxisModel = {
valueType: 'Category',
majorGridLines: {
color: 'blue',
width: 1
},
minorGridLines: {
color: 'red',
width: 0
}
};
const primaryyAxis: AxisModel = {
title: 'Temperature (Fahrenheit)',
majorGridLines: {
color: 'blue',
width: 1
},
minorGridLines: {
color: 'red',
width: 0
}
};
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Temperature flow over months'>
<Inject services={[ColumnSeries, Legend, Tooltip, DataLabel, Category]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={categoryData} xName='country' yName='gold' name='Sales' type='Column'>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let categoryData = [
{ country: "Russia", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "United States", gold: 30, silver: 25, bronze: 27 }
];
export let categoryData: Object[] = [
{ country: "Russia", gold: 50, silver: 70, bronze: 45 },
{ country: "China", gold: 40, silver: 60, bronze: 55 },
{ country: "Japan", gold: 70, silver: 60, bronze: 50 },
{ country: "Australia", gold: 60, silver: 56, bronze: 40 },
{ country: "France", gold: 50, silver: 45, bronze: 35 },
{ country: "Germany", gold: 40, silver: 30, bronze: 22 },
{ country: "Italy", gold: 40, silver: 35, bronze: 37 },
{ country: "United States", gold: 30, silver: 25, bronze: 27 }
];
Multiple Axis
In addition to primary X and Y axis, we can add n number of axis to the chart. Series can be associated with this axis, by mapping with axis’s unique name.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, AxesDirective, AxisDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, Tooltip, DataLabel, LineSeries } from '@syncfusion/ej2-react-charts';
import { PaneData } from './datasource';
function App() {
const primaryxAxis = { valueType: 'Category' };
const primaryyAxis = {
title: 'Temperature (Fahrenheit)', minimum: 0, maximum: 90, interval: 10,
lineStyle: { width: 0 }, labelFormat: '{value}°F'
};
const marker = { visible: true, width: 10, height: 10, border: { width: 2, color: '#F8AB1D' } };
const lines = { width: 0 };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Temperature flow over months'>
<Inject services={[ColumnSeries, LineSeries, Legend, Tooltip, DataLabel, Category]}/>
<AxesDirective>
<AxisDirective rowIndex={0} name='yAxis1' opposedPosition={true} title='Temperature (Celsius)' majorGridLines={lines} lineStyle={lines}>
</AxisDirective>
</AxesDirective>
<SeriesCollectionDirective>
<SeriesDirective dataSource={PaneData} xName='x' yName='y' name='Germany' type='Column'>
</SeriesDirective>
<SeriesDirective dataSource={PaneData} xName='x' yName='y1' name='Japan' type='Line' marker={marker} yAxisName='yAxis1'>
</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, LineSeries, Selection } from '@syncfusion/ej2-react-charts';
import { PaneData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { valueType: 'Category' };
const primaryyAxis: AxisModel = {
title: 'Temperature (Fahrenheit)', minimum: 0, maximum: 90, interval: 10,
lineStyle: { width: 0 }, labelFormat: '{value}°F'
};
const marker = { visible: true, width: 10, height: 10, border: { width: 2, color: '#F8AB1D' } };
const lines = { width: 0 };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Temperature flow over months'>
<Inject services={[ColumnSeries, LineSeries, Legend, Tooltip, DataLabel, Category]} />
<AxesDirective>
<AxisDirective rowIndex={0} name='yAxis1' opposedPosition={true} title='Temperature (Celsius)'
majorGridLines={lines} lineStyle={lines} >
</AxisDirective>
</AxesDirective>
<SeriesCollectionDirective>
<SeriesDirective dataSource={PaneData} xName='x' yName='y' name='Germany' type='Column'>
</SeriesDirective>
<SeriesDirective dataSource={PaneData} xName='x' yName='y1' name='Japan' type='Line'
marker={marker} yAxisName='yAxis1' >
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let PaneData = [
{ x: 'Jan', y: 15, y1: 33 }, { x: 'Feb', y: 20, y1: 31 },
{ x: 'Mar', y: 35, y1: 30 }, { x: 'Apr', y: 40, y1: 28 },
{ x: 'May', y: 80, y1: 29 }, { x: 'Jun', y: 70, y1: 30 },
{ x: 'Jul', y: 65, y1: 33 }, { x: 'Aug', y: 55, y1: 32 },
{ x: 'Sep', y: 50, y1: 34 }, { x: 'Oct', y: 30, y1: 32 },
{ x: 'Nov', y: 35, y1: 32 }, { x: 'Dec', y: 35, y1: 31 }
];
export let PaneData: Object[] = [
{ x: 'Jan', y: 15, y1: 33 }, { x: 'Feb', y: 20, y1: 31 },
{ x: 'Mar', y: 35, y1: 30 }, { x: 'Apr', y: 40, y1: 28 },
{ x: 'May', y: 80, y1: 29 }, { x: 'Jun', y: 70, y1: 30 },
{ x: 'Jul', y: 65, y1: 33 }, { x: 'Aug', y: 55, y1: 32 },
{ x: 'Sep', y: 50, y1: 34 }, { x: 'Oct', y: 30, y1: 32 },
{ x: 'Nov', y: 35, y1: 32 }, { x: 'Dec', y: 35, y1: 31 }
];
Inversed Axis
When an axis is inversed, highest value of the axis comes closer to origin and vice versa. To place an axis in inversed manner set this property isInversed
to true.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, DataLabel } from '@syncfusion/ej2-react-charts';
import { inverseData } from './datasource';
function App() {
const primaryxAxis = { title: 'Years', opposedPosition: true, isInversed: true };
const primaryyAxis = { title: 'Exchange rate (INR per USD)', isInversed: true };
const marker = { dataLabel: { visible: true } };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Exchange Rate'>
<Inject services={[ColumnSeries, Category, Legend, DataLabel]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={inverseData} xName='x' yName='y' type='Column' marker={marker}>
</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, DataLabel } from '@syncfusion/ej2-react-charts';
import { inverseData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Years', opposedPosition: true, isInversed: true };
const primaryyAxis: AxisModel = { title: 'Exchange rate (INR per USD)', isInversed: true };
const marker = { dataLabel: { visible: true } };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Exchange Rate'>
<Inject services={[ColumnSeries, Category, Legend, DataLabel]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={inverseData} xName='x' yName='y' type='Column' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let inverseData = [
{ x: 2008, y: 15.1 },
{ x: 2009, y: 16 },
{ x: 2010, y: 21.4 },
{ x: 2011, y: 18 },
{ x: 2012, y: 16.2 },
{ x: 2013, y: 11 },
{ x: 2014, y: 7.6 },
{ x: 2015, y: 1.5 }
];
export let inverseData: Object[] = [
{ x: 2008, y: 15.1 },
{ x: 2009, y: 16 },
{ x: 2010, y: 21.4 },
{ x: 2011, y: 18 },
{ x: 2012, y: 16.2 },
{ x: 2013, y: 11 },
{ x: 2014, y: 7.6 },
{ x: 2015, y: 1.5 }
];
Opposed Position
To place an axis opposite from its original position, set opposedPosition
property of the axis to true.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { ChartComponent, SeriesCollectionDirective, SeriesDirective, Inject, ColumnSeries, Legend, Category, DataLabel } from '@syncfusion/ej2-react-charts';
import { inverseData } from './datasource';
function App() {
const primaryxAxis = { title: 'Years', opposedPosition: true };
const primaryyAxis = { title: 'Exchange rate (INR per USD)' };
const marker = { dataLabel: { visible: true } };
return <ChartComponent id='charts' primaryXAxis={primaryxAxis} primaryYAxis={primaryyAxis} title='Exchange Rate'>
<Inject services={[ColumnSeries, Category, Legend, DataLabel]}/>
<SeriesCollectionDirective>
<SeriesDirective dataSource={inverseData} xName='x' yName='y' type='Column' marker={marker}>
</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, DataLabel } from '@syncfusion/ej2-react-charts';
import { inverseData } from './datasource';
function App() {
const primaryxAxis: AxisModel = { title: 'Years', opposedPosition: true };
const primaryyAxis: AxisModel = { title: 'Exchange rate (INR per USD)' };
const marker = { dataLabel: { visible: true } };
return <ChartComponent id='charts'
primaryXAxis={primaryxAxis}
primaryYAxis={primaryyAxis}
title='Exchange Rate'>
<Inject services={[ColumnSeries, Category, Legend, DataLabel]} />
<SeriesCollectionDirective>
<SeriesDirective dataSource={inverseData} xName='x' yName='y' type='Column' marker={marker}>
</SeriesDirective>
</SeriesCollectionDirective>
</ChartComponent>
};
export default App;
ReactDOM.render(<App />, document.getElementById("charts"));
export let inverseData = [
{ x: 2008, y: 15.1 },
{ x: 2009, y: 16 },
{ x: 2010, y: 21.4 },
{ x: 2011, y: 18 },
{ x: 2012, y: 16.2 },
{ x: 2013, y: 11 },
{ x: 2014, y: 7.6 },
{ x: 2015, y: 1.5 }
];
export let inverseData: Object[] = [
{ x: 2008, y: 15.1 },
{ x: 2009, y: 16 },
{ x: 2010, y: 21.4 },
{ x: 2011, y: 18 },
{ x: 2012, y: 16.2 },
{ x: 2013, y: 11 },
{ x: 2014, y: 7.6 },
{ x: 2015, y: 1.5 }
];