Your search did not match any results.
Point Charts

Custom Axis Position

The Chart widget initially displays axes along pane borders. Several other predefined axis layout options are available. In this demo, the customPosition option is used to move each axis, so that it is displayed on the specified value of another axis. When you position the argument axis, use values from the value axis (in the same type and format) and vice versa.

Regardless of which automatic axis layout type you use, the Chart Control allows you to apply manual offsets. Specify the offset option in pixels to keep the axis position unchanged when users scroll or zoom the Chart data. The offset option shifts the axis from the specified position as follows:

  • If the axis is horizontal, a negative offset shifts the axis to the top, a positive offset shifts it to the bottom.

  • If the axis is vertical, a negative offset shifts the axis to the left, a positive offset shifts it to the right.

In this demo, you can use controls under the Chart to change the customPosition and offset options for both axes.

Copy to CodeSandBox
Apply
Reset
import React from 'react'; import NumberBox from 'devextreme-react/number-box'; import { Chart, CommonSeriesSettings, Series, Point, ArgumentAxis, ValueAxis, Legend, } from 'devextreme-react/chart'; import { generateDataSource } from './data.js'; const dataSource = generateDataSource(); class App extends React.Component { constructor(props) { super(props); this.state = { argumentCustomPosition: 0, argumentOffset: 0, valueCustomPosition: 0, valueOffset: 0 }; this.changeArgumentPosition = (e) => { this.setState({ argumentCustomPosition: e.value }); }; this.changeArgumentOffset = (e) => { this.setState({ argumentOffset: e.value }); }; this.changeValuePosition = (e) => { this.setState({ valueCustomPosition: e.value }); }; this.changeValueOffset = (e) => { this.setState({ valueOffset: e.value }); }; } render() { const { argumentCustomPosition, argumentOffset, valueCustomPosition, valueOffset } = this.state; return ( <div> <Chart id="chart" dataSource={dataSource} > <CommonSeriesSettings type='scatter' /> <Series argumentField='x1' valueField='y1' /> <Series argumentField='x2' valueField='y2'> <Point symbol='triangleDown' /> </Series> <ArgumentAxis defaultVisualRange={[-20, 20]} customPosition={argumentCustomPosition} offset={argumentOffset} /> <ValueAxis defaultVisualRange={[-20, 20]} customPosition={valueCustomPosition} offset={valueOffset} endOnTick={false} /> <Legend visible={false} /> </Chart> <div className='options'> <div className='caption'>Options</div> <div className="common"> <div className='block left'> <span>Argument Axis</span> <div className='option'> <span>Custom position:</span> <NumberBox value={argumentCustomPosition} showSpinButtons={true} onValueChanged={this.changeArgumentPosition} /> </div> <div className='option'> <span>Offset:</span> <NumberBox value={argumentOffset} showSpinButtons={true} onValueChanged={this.changeArgumentOffset} /> </div> </div> <div className='block right'> <span>Value Axis</span> <div className='option'> <span>Custom position:</span> <NumberBox value={valueCustomPosition} showSpinButtons={true} onValueChanged={this.changeValuePosition} /> </div> <div className='option'> <span>Offset:</span> <NumberBox value={valueOffset} showSpinButtons={true} onValueChanged={this.changeValueOffset} /> </div> </div> </div> </div> </div> ); } } export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app') );
<!DOCTYPE html> <html> <head> <title>DevExtreme Demo</title> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.1.7/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.1.7/css/dx.light.css" /> <link rel="stylesheet" type="text/css" href="styles.css" /> <script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script> <script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script> <script type="text/javascript" src="config.js"></script> <script type="text/javascript"> System.import('./index.js'); </script> </head> <body class="dx-viewport"> <div class="demo-container"> <div id="app"></div> </div> </body> </html>
.options { padding: 20px; margin-top: 20px; background-color: rgba(191, 191, 191, 0.15); } .option { margin-top: 10px; overflow: auto; } .option > span { margin-right: 20px; margin-top: 6px; float: left; } .caption { font-size: 18px; font-weight: 700; } .option > .dx-numberbox { width: 90px; float: right; } .common { width: 488px; } .block { vertical-align: middle; margin-top: 10px; } .left { display: inline-block; } .right { float: right; } .block > span { font-size: 18px; font-weight: 500; }
export function generateDataSource() { let x1, x2, y1, y2, i; const ds = []; for (i = 0; i < 20; i++) { x1 = random(5, 15); y1 = random(5, 15); ds.push({ x1: x1, y1: y1, x2: x2, y2: y2 }); } for (i = 0; i < 20; i++) { x2 = random(5, 15); y2 = random(-15, -5); ds.push({ x1: x1, y1: y1, x2: x2, y2: y2 }); } for (i = 0; i < 20; i++) { x2 = random(-15, -5); y2 = random(5, 15); ds.push({ x1: x1, y1: y1, x2: x2, y2: y2 }); } for (i = 0; i < 20; i++) { x1 = random(-15, -5); y1 = random(-15, -5); ds.push({ x1: x1, y1: y1, x2: x2, y2: y2 }); } return ds; } function random(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }
System.config({ transpiler: 'plugin-babel', meta: { }, paths: { 'npm:': 'https://unpkg.com/' }, defaultExtension: 'js', map: { 'react': 'npm:react@16/umd/react.development.js', 'react-dom': 'npm:react-dom@16/umd/react-dom.development.js', 'prop-types': 'npm:prop-types/prop-types.js', 'devextreme': 'npm:devextreme@20.1', 'devextreme-react': 'npm:devextreme-react@20.1', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram@1.0.14', 'devexpress-gantt': 'npm:devexpress-gantt@1.0.7', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js' }, packages: { 'devextreme': { defaultExtension: 'js' }, 'devextreme-react': { main: 'index.js' }, 'devextreme/events/utils': { main: 'index' }, 'devextreme/events': { main: 'index' }, }, babelOptions: { sourceMaps: false, stage0: true, react: true } });