DevExtreme DataSource
To get the DataSource instance, call the Sankey's getDataSource() method:
jQuery
function getDataSource() { return $("#sankeyContainer").dxSankey("getDataSource"); }
Angular
import { Component, ViewChild } from '@angular/core'; import { DxSankeyComponent } from 'devextreme-angular'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { @ViewChild(DxSankeyComponent, { static: false }) sankey: DxSankeyComponent; // Prior to Angular 8 // @ViewChild(DxSankeyComponent) sankey: DxSankeyComponent; getDataSource() { return this.sankey.instance.getDataSource(); } }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxSankeyModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxSankeyModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
<template> <DxSankey :ref="sankeyRefKey"> <!-- ... --> </DxSankey> </template> <script> import DxSankey from 'devextreme-vue/sankey'; const sankeyRefKey = "my-sankey"; export default { components: { DxSankey }, data() { return { sankeyRefKey } }, methods: { getDataSource: function() { return this.sankey.getDataSource(); } }, computed: { sankey: function() { return this.$refs[sankeyRefKey].instance; } } } </script>
React
import { useRef } from 'react'; import Sankey from 'devextreme-react/sankey'; export default function App() { const sankey = useRef(null); const getDataSource = () => { return sankey.current.instance().getDataSource(); } return ( <Sankey ref={sankey}> {/* ... */} </Sankey> ); }
Then, access the underlying store with the store() method, and call the store's push(changes) method to modify data. The Sankey will be updated automatically.
getDataSource().store().push([ { type: "update", key: "Oranges", data: { count: 10 } }, { type: "remove", key: "Apples" } ]);
See Also
JavaScript Array
jQuery
You can use the standard methods to make changes to the array. Then, use the option(optionName, optionValue) method to reassign the updated array to the Sankey.
var sankeyData = [ { source: "Brazil", target: "Spain", weight: 4 }, { source: "Brazil", target: "Portugal", weight: 5 }, { source: "Brazil", target: "England", weight: 2 }, { source: "Canada", target: "Portugal", weight: 2 }, { source: "Canada", target: "England", weight: 1 }, { source: "Mexico", target: "Portugal", weight: 9 }, { source: "Mexico", target: "Spain", weight: 5 } ]; sankeyData.push({ source: "Mexico", target: "Spain", weight: 2 }); // Reassigns the "sankeyData" array to the Sankey $("#sankeyContainer").dxSankey("option", "dataSource", sankeyData);
See Also
Angular
Enclose the dataSource property in square brackets to bind it to an array using one-way binding. Now, whenever an item is added or removed from the array, the Sankey is updated accordingly.
<dx-sankey [dataSource]="sankeyData"> </dx-sankey>
import { DxSankeyModule } from "devextreme-angular"; // ... export class AppComponent { sankeyData: Array<{ source: string, target: string, weight: number }> = [ { source: "Brazil", target: "Spain", weight: 4 }, { source: "Brazil", target: "Portugal", weight: 5 }, { source: "Brazil", target: "England", weight: 2 }, { source: "Canada", target: "Portugal", weight: 2 }, { source: "Canada", target: "England", weight: 1 }, { source: "Mexico", target: "Portugal", weight: 9 }, { source: "Mexico", target: "Spain", weight: 5 } ]; } @NgModule({ imports: [ // ... DxSankeyModule ], // ... })
Vue
Bind the dataSource property to an array using one-way binding. Now, whenever an item is added or removed from the array, the Sankey is updated accordingly.
React
Bind the dataSource property to an array using one-way binding. Now, whenever an item is added or removed from the array, the Sankey is updated accordingly.
If you have technical questions, please create a support ticket in the DevExpress Support Center.