# 这是关系合并成一条线的代码 links=[] for idx, row in data3.iterrows(): source, target = name_dict.get(idx[0]), name_dict.get(idx[1]) value = ','.join([f'{col}{row[col]}次'for col in row.index if row[col] !=0]) color = [col for col in row.index if row[col] !=0] if len(color) > 1: color = colors[len(color) + 2] else: color = colors[['同住人', '同车厢人员', '同飞机', '同飞机订票'].index(color[0])] links.append({ "source": source, "target": target, 'lineStyle': {'curveness': 0.1, 'color': color}, # 设置线条曲度、颜色 "value": value # 设置线条标签值 })
# -------------------------------- 分割线 --------------------------------------------- # 这是每条关系都生成一条线的代码 links=[] for idx, row in data3.iterrows(): source, target = name_dict.get(idx[0]), name_dict.get(idx[1]) for i, col in enumerate(row.index): if row[col] != 0: links.append({ "source": source, "target": target, 'lineStyle': {'curveness': (i+1) / 10, 'color': colors[i % 4]}, # 设置线条曲度、颜色 "value": f"{col}{row[col]}次"# 设置线条标签值 })
<scripttype="text/javascript"> var dom = document.getElementById('container'); var myChart = echarts.init(dom, null, { renderer: 'canvas', useDirtyRect: false }); var app = {};
defwrite_html(nodes: list, links: list, filename: pl.Path): """ 写入静态html :return: """ with open('model/graph_model.html', 'r', encoding='utf-8') as fin: html = fin.read() for old, new in {'replace_data': str(self.nodes), 'replace_links': str(links)}.items(): html = html.replace(old, new) out_path = filename.parent / f'{filename.stem}.html' with open(out_path, 'w', encoding='utf-8') as fout: fout.write(html) print(f'完成{filename.name}的读取分析,画图文件输出为{out_path}')