private initChart() { this.chart = echarts.init(this.$el as HTMLDivElement)…
- User
private initChart() { this.chart = echarts.init(this.$el as HTMLDivElement) this.chart.setOption({ tooltip: {}, animationDurationUpdate: 1500, animationEasingUpdate: 'quinticInOut', series: [ { type: 'graph', layout: 'none', symbolSize: 45, roam: true, label: { show: true }, edgeSymbol: ['circle', 'arrow'], edgeSymbolSize: [4, 7], edgeLabel: { fontSize: 10, }, itemStyle: { color: '#fff', borderColor: '#9DA2F2', borderWidth: 1 }, hoverAnimation: true, data: [ { name: 'Node 1', x: 300, y: 300 }, { name: 'Node 2', x: 800, y: 300 }, { name: 'Node 3', x: 550, y: 100 }, { name: 'Node 4', x: 550, y: 500 } ], // links: [], links: [ { source: 'Node 1', target: 'Node 3' }, { source: 'Node 2', target: 'Node 3' }, { source: 'Node 2', target: 'Node 4' }, { source: 'Node 1', target: 'Node 4' } ], lineStyle: { opacity: 0.9, width: 2, curveness: 0 } } ] }) }
@Prop() readonly groups: Group[]
export interface Group { annotation: string id: number name: string westsiteid: number eastsiteid: number }
vue 2 js как добавить данные с помощью пропса groups в initChart, чтобы отображалось westsiteid вместо source: 'Node 1',
- Assistant
Чтобы добавить данные из пропса
groupsвinitChart, вы можете сделать следующее:- Вначале определите тип для пропса
groupsв компоненте:
@Prop() readonly groups: Group[]- Обновите метод
initChart, чтобы использовать данные из пропсаgroups:
private initChart() { this.chart = echarts.init(this.$el as HTMLDivElement) // Создайте массив для данных узлов const nodesData = this.groups.map((group, index) => ({ name: `Node ${index + 1}`, x: group.westsiteid, y: group.eastsiteid })) // Создайте массив для данных связей const linksData = this.groups.map((group, index) => ({ source: `Node ${index + 1}`, target: group.name })) // Установите опции графика, используя данные узлов и связей this.chart.setOption({ tooltip: {}, animationDurationUpdate: 1500, animationEasingUpdate: 'quinticInOut', series: [ { type: 'graph', layout: 'none', symbolSize: 45, roam: true, label: { show: true }, edgeSymbol: ['circle', 'arrow'], edgeSymbolSize: [4, 7], edgeLabel: { fontSize: 10, }, itemStyle: { color: '#fff', borderColor: '#9DA2F2', borderWidth: 1 }, hoverAnimation: true, data: nodesData, // Используйте данные узлов links: linksData, // Используйте данные связей lineStyle: { opacity: 0.9, width: 2, curveness: 0 } } ] }) } - Вначале определите тип для пропса