Your search did not match any results.
Charts

SignalR Service

Documentation

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.

Apply
Reset
<template> <div v-if="connectionStarted"> <dx-chart id="chart" ref="chart" :data-source="dataSource" :margin="{right: 30}" :customize-point="customizePoint" zooming-mode="all" scrolling-mode="all" title="Stock Price" > <dx-series argument-field="date" type="candlestick" pane="Price" > <dx-aggregation :enabled="true" :calculate="calculateCandle" method="custom" /> </dx-series> <dx-series argument-field="date" value-field="volume" type="bar" color="red" pane="Volume" name="Volume" > <dx-aggregation :enabled="true" method="sum" /> </dx-series> <dx-pane name="Price"/> <dx-pane :height="80" name="Volume" /> <dx-legend :visible="false"/> <dx-argument-axis :min-visual-range-length="{minutes: 10}" :visual-range="{length: 'hour'}" argument-type="datetime" /> <dx-zoom-and-pan argument-axis="both"/> <dx-value-axis :placeholder-size="50"/> <dx-scroll-bar :visible="true"/> <dx-loading-indicator :enabled="true"/> <dx-tooltip :enabled="true" :shared="true" argument-format="shortDateShortTime" content-template="tooltipTemplate" /> <dx-crosshair :enabled="true" :horizontal-line="{visible: false}" /> <template #tooltipTemplate="{ data }"> <tooltip-template :point-info="data"/> </template> </dx-chart> </div> </template> <script> import { DxChart, DxArgumentAxis, DxValueAxis, DxAggregation, DxSeries, DxLegend, DxScrollBar, DxZoomAndPan, DxLoadingIndicator, DxPane, DxTooltip, DxCrosshair } from 'devextreme-vue/chart'; import CustomStore from 'devextreme/data/custom_store'; import TooltipTemplate from './TooltipTemplate.vue'; import { HubConnectionBuilder } from '@aspnet/signalr'; export default { components: { DxChart, DxArgumentAxis, DxValueAxis, DxAggregation, DxLegend, DxSeries, DxScrollBar, DxZoomAndPan, DxLoadingIndicator, DxPane, DxTooltip, DxCrosshair, TooltipTemplate }, data() { return { connectionStarted: false, dataSource: null, 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] }; } }, customizePoint: arg => { if(arg.seriesName === 'Volume') { const point = this.$refs.chart.instance.getAllSeries()[0].getPointsByArg(arg.argument)[0].data; if(point.close >= point.open) { return { color: '#1db2f5' }; } } } }; }, mounted() { var hubConnection = new HubConnectionBuilder() .withUrl('https://js.devexpress.com/Demos/NetCore/stockTickDataHub') .build(); var store = new CustomStore({ load: () => hubConnection.invoke('getAllData'), key: 'date' }); hubConnection .start() .then(() => { hubConnection.on('updateStockPrice', (data) => { store.push([{ type: 'insert', key: data.date, data: data }]); }); this.dataSource = store; this.connectionStarted = true; }); } }; </script> <style> #chart { height: 440px; } </style>
<template> <div class="tooltip-template"> <div>{{ pointInfo.argumentText }}</div> <div><span>Open: </span> {{ formatCurrency(prices.openValue, "USD") }} </div> <div><span>High: </span> {{ formatCurrency(prices.highValue, "USD") }} </div> <div><span>Low: </span> {{ formatCurrency(prices.lowValue, "USD") }} </div> <div><span>Close: </span> {{ formatCurrency(prices.closeValue, "USD") }} </div> <div><span>Volume: </span> {{ formatNumber(volume.value, { maximumFractionDigits: 0 }) }} </div> </div> </template> <script> export default { props: { pointInfo: { type: Object, default: () => {} } }, data() { return { volume: this.pointInfo.points.filter(point => point.seriesName === 'Volume')[0], prices: this.pointInfo.points.filter(point => point.seriesName !== 'Volume')[0] }; }, methods: { formatCurrency: new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 0 } ).format, formatNumber: new Intl.NumberFormat('en-US', { minimumFractionDigits: 0 }).format }, }; </script> <style> .tooltip-template span { font-weight: 500; } </style>
import Vue from 'vue'; import App from './App.vue'; new Vue({ el: '#app', components: { App }, template: '<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/19.2.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/19.2.3/css/dx.light.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"> <span v-if="false">Loading...</span> </div> </div> </body> </html>
System.config({ transpiler: 'plugin-babel', paths: { 'npm:': 'https://unpkg.com/' }, map: { vue: 'npm:vue@2.6.3/dist/vue.esm.browser.js', 'vue-loader': 'npm:dx-systemjs-vue-browser@latest/index.js', 'devextreme': 'npm:devextreme@19.2', 'devextreme-vue': 'npm:devextreme-vue@19.2', jszip: 'npm:jszip@3.1.3/dist/jszip.min.js', 'quill': 'npm:quill@1.3.7/dist/quill.js', 'devexpress-diagram': 'npm:devexpress-diagram', 'devexpress-gantt': 'npm:devexpress-gantt', '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' }, meta: { '*.vue': { loader: 'vue-loader' } }, packages: { 'devextreme-vue': { main: 'index.js' }, 'devextreme': { defaultExtension: 'js' } }, babelOptions: { sourceMaps: false, stage0: true } });