Your search did not match any results.
Charts

SignalR Service

This example demonstrates real-time data update in a financial chart bound to a SignalR server. Note that data used in this demo is for demonstration purposes only.

Copy to CodeSandBox
Apply
Reset
import React from 'react'; import Chart, { ArgumentAxis, ValueAxis, Aggregation, Legend, Series, ScrollBar, ZoomAndPan } from 'devextreme-react/chart'; import CustomStore from 'devextreme/data/custom_store'; import { HubConnectionBuilder } from '@aspnet/signalr'; class App extends React.Component { constructor(props) { super(props); this.state = { connectionStarted: false }; const hubConnection = new HubConnectionBuilder() .withUrl('/Demos/NetCore/stockTickDataHub') .build(); const store = new CustomStore({ load: () => hubConnection.invoke('getAllData'), key: 'date' }); this.dataSource = store; hubConnection .start() .then(() => { hubConnection.on('updateStockPrice', (data) => { store.push([{ type: 'insert', key: data.date, data: data }]); }); this.setState({ connectionStarted: true }); }); } calculateCandle(e) { const prices = e.data.map(d => d.price); if (prices.length) { return { date: e.intervalStart, open: prices[0], high: Math.max.apply(null, prices), low: Math.min.apply(null, prices), close: prices[prices.length - 1] }; } } zoomEnd(e) { if (e.range.endValue - e.range.startValue < 1000 * 60 * 10) { e.cancel = true; } } render() { return ( <div> {this.state.connectionStarted && (<Chart id={'chart'} dataSource={this.dataSource} margin={{ right: 30 }} onZoomEnd={this.zoomEnd} title={'Stock Price'}> <Series argumentField={'date'} type={'CandleStick'}> <Aggregation enabled={true} method={'custom'} calculate={this.calculateCandle} /> </Series> <Legend visible={false} /> <ArgumentAxis argumentType={'datetime'} valueMarginsEnabled={false} visualRange={{ length: 'hour' }} /> <ValueAxis placeholderSize={50} /> <ZoomAndPan argumentAxis={'both'} /> <ScrollBar visible={true} /> </Chart>) } </div> ); } } export default App;
import React from 'react'; import ReactDOM from 'react-dom'; import App from './App.js'; ReactDOM.render( <App />, document.getElementById('app') );
<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/18.2.3/css/dx.common.css" /> <link rel="dx-theme" data-theme="generic.light" href="https://cdn3.devexpress.com/jslib/18.2.3/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>
#chart { height: 440px; }
System.config({ transpiler: 'plugin-babel', 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@18.2', 'devextreme-react': 'npm:devextreme-react@18.2', 'jszip': 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.6/dist/quill.js', 'quill-delta-to-html': 'npm:quill-delta-to-html@0.10.4/dist/browser/QuillDeltaToHtmlConverter.bundle.js', // SystemJS plugins 'plugin-babel': 'npm:systemjs-plugin-babel@0/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel@0/systemjs-babel-browser.js', 'tslib': 'npm:tslib@1.6.1', '@aspnet/signalr': 'npm:@aspnet/signalr@1.0.0/dist/cjs/index.js', }, packages: { 'devextreme': { defaultExtension: 'js' }, 'devextreme-react': { main: 'index.js' } }, babelOptions: { sourceMaps: false, stage0: true, react: true } });