AmCharts (V4) 中的样式工具提示
styling tooltips in AmCharts (V4)
目前我正在尝试设置当您将鼠标悬停在具有动态内容(公司名称)的地图图像上时出现的工具提示的样式。
我的目标是将背景样式设置为特定颜色,为字体指定颜色并应用 CSS 属性 "box-shadow".
为了第一个目标,我尝试像这样使用 "fill" 属性:
mapImageSeries 的类型为 am4maps.MapImageSeries。
this.mapImageSeries.tooltip.fill = am4core.color('#ffff00');
但使用
无效
this.mapImageSeries.tooltip.background.cornerRadius = 0; // will change the "border-radius" of the tooltip.
this.mapImageSeries.tooltip.background.fill = am4core.color('#ffff00'); // does also not work.
我的第二个目标是为字体设置颜色 属性,我没有找到 属性,与框阴影 css 属性 一样。
是否可以为工具提示附加 css class,以便我可以通过 CSS 轻松设置样式?以及如何使用工具提示设置样式
我面临的要求?
默认情况下,工具提示会从相关对象中提取颜色,因此要操纵它们的样式,您首先必须 turn that off,例如:
this.mapImageSeries.tooltip.getFillFromObject = false;
然后你可以这样做:
this.mapImageSeries.tooltip.background.cornerRadius = 0;
this.mapImageSeries.tooltip.background.fill = am4core.color("#ffff00");
您可以应用 the DropShadow
SVG filter 而不是修改 CSS box-shadow
。 Tooltip
s 有一个过滤器,实际上是一个 DropShadow
过滤框,我们可以修改它:
var dropShadow = this.mapImageSeries.tooltip.filters.getIndex(0);
dropShadow.dx = 3;
dropShadow.dy = 3;
dropShadow.blur = 5;
dropShadow.opacity = 0.7;
为了修改 Tooltip
文本样式,他们实际上通过 label
属性 拥有自己的 Label
子项。有两种方法可以修改颜色,第一种是像上面的方法,例如如果要为工具提示文本设置默认颜色:
this.mapImageSeries.tooltip.label.fill = am4core.color("#e97f02"); // color from lolcolors: https://www.webdesignrankings.com/resources/lolcolors/#palette_18
另一种为文本着色以及应用其他 CSS 样式的方法是在 tooltipText
字符串中使用 Visual formatting,例如:
this.mapImageSeries.tooltipText = "[font-size: 20px; #bd1550]{companyTitle}:[/]\n{locationTitle} branch";
无法通过视觉格式设置的一种样式是 text-align
,您需要通过 SVG 属性来实现,例如
this.mapImageSeries.tooltip.label.textAlign = "middle";
我在这里为您制作了一个演示:
https://codepen.io/team/amcharts/pen/f6d4167ea7ccd5dd47054d2430443c0a/
希望这对您有所帮助,如果一切都有意义,请告诉我。
如果您仍然希望根据自己的需要使用 CSS,请告诉我,我会尽力与您一起解决这个问题。
目前我正在尝试设置当您将鼠标悬停在具有动态内容(公司名称)的地图图像上时出现的工具提示的样式。
我的目标是将背景样式设置为特定颜色,为字体指定颜色并应用 CSS 属性 "box-shadow".
为了第一个目标,我尝试像这样使用 "fill" 属性:
mapImageSeries 的类型为 am4maps.MapImageSeries。
this.mapImageSeries.tooltip.fill = am4core.color('#ffff00');
但使用
无效this.mapImageSeries.tooltip.background.cornerRadius = 0; // will change the "border-radius" of the tooltip.
this.mapImageSeries.tooltip.background.fill = am4core.color('#ffff00'); // does also not work.
我的第二个目标是为字体设置颜色 属性,我没有找到 属性,与框阴影 css 属性 一样。
是否可以为工具提示附加 css class,以便我可以通过 CSS 轻松设置样式?以及如何使用工具提示设置样式 我面临的要求?
默认情况下,工具提示会从相关对象中提取颜色,因此要操纵它们的样式,您首先必须 turn that off,例如:
this.mapImageSeries.tooltip.getFillFromObject = false;
然后你可以这样做:
this.mapImageSeries.tooltip.background.cornerRadius = 0;
this.mapImageSeries.tooltip.background.fill = am4core.color("#ffff00");
您可以应用 the DropShadow
SVG filter 而不是修改 CSS box-shadow
。 Tooltip
s 有一个过滤器,实际上是一个 DropShadow
过滤框,我们可以修改它:
var dropShadow = this.mapImageSeries.tooltip.filters.getIndex(0);
dropShadow.dx = 3;
dropShadow.dy = 3;
dropShadow.blur = 5;
dropShadow.opacity = 0.7;
为了修改 Tooltip
文本样式,他们实际上通过 label
属性 拥有自己的 Label
子项。有两种方法可以修改颜色,第一种是像上面的方法,例如如果要为工具提示文本设置默认颜色:
this.mapImageSeries.tooltip.label.fill = am4core.color("#e97f02"); // color from lolcolors: https://www.webdesignrankings.com/resources/lolcolors/#palette_18
另一种为文本着色以及应用其他 CSS 样式的方法是在 tooltipText
字符串中使用 Visual formatting,例如:
this.mapImageSeries.tooltipText = "[font-size: 20px; #bd1550]{companyTitle}:[/]\n{locationTitle} branch";
无法通过视觉格式设置的一种样式是 text-align
,您需要通过 SVG 属性来实现,例如
this.mapImageSeries.tooltip.label.textAlign = "middle";
我在这里为您制作了一个演示:
https://codepen.io/team/amcharts/pen/f6d4167ea7ccd5dd47054d2430443c0a/
希望这对您有所帮助,如果一切都有意义,请告诉我。
如果您仍然希望根据自己的需要使用 CSS,请告诉我,我会尽力与您一起解决这个问题。