【发布时间】:2019-01-24 14:22:11
【问题描述】:
有没有办法在 amcharts 4 中使用 sprites 动态构建 SVG?
示例:screenhot
有 20 种不同的类型,用颜色表示。 每个引脚可以包含多种类型。 例如,一个图钉有 3 种类型,由 3 种颜色组成。
我有一个圆形的 SVG 路径。 使用常规的 JS 和 SVG,我可以为每种类型创建路径并更改笔触颜色、strokedasharray 和 strokedashoffset。 这会产生具有 3 种颜色的漂亮圆圈。
然而这似乎不可能用 amcharts 4 来做。
对于初学者,strokedashoffset 甚至不是精灵支持的属性。你为什么要费心支持strokedasharray然后忽略strokedashoffet?!
第二个问题是找出如何将数据传递给精灵。
这是我传递给 mapImageSeries 类的数据对象示例。
[{
amount: 3,
client: undefined,
colorsArr: {0: "#FFB783", 1: "#FD9797", 2: "#77A538"},
dashArray: "500,1000",
dashOffset: 1500,
divided: 500,
global: true,
groupId: "minZoom-1",
hcenter: "middle",
id: "250",
latitude: 50.53398,
legendNr: 8,
longitude: 9.68581,
name: "Fulda",
offsetsArr: {0: 0, 1: 500, 2: 1000},
scale: 0.5,
title: "Fulda",
typeIds: (3) ["4", "18", "21"],
typeMarker: " type-21 type-18 type-4",
vcenter: "bottom",
zoomLevel: 5
}]
似乎不可能将颜色传递给精灵。
var svgPath = 'M291,530C159,530,52,423,52,291S159,52,291,52s239,107,239,239c0,131.5-106.3,238.3-237.7,239'
var mainPin1 = single.createChild(am4core.Sprite)
mainPin1.strokeWidth = 100
mainPin1.fill = am4core.color('#fff')
mainPin1.stroke = am4core.color('#ff0000')
mainPin1.propertyFields.strokeDasharray = 'dashArray'
mainPin1.propertyFields.strokeDashoffset = 'dashOffset'
mainPin1.path = svgPath
mainPin1.scale = 0.04
mainPin1.propertyFields.horizontalCenter = 'hcenter'
mainPin1.propertyFields.verticalCenter = 'vbottom'
【问题讨论】: