简体   繁体   English

从highcharts中的svg中删除内联样式

[英]remove inline styles from svg in highcharts

I have recently started looking at Highcharts for a project and so far I have managed to get the charts I need but the only problem I have is the excessive markup bloat which is created along with the charts. 我最近开始在一个项目中查看Highcharts,到目前为止我已经设法获得了我需要的图表,但我唯一的问题是与图表一起创建的过多标记膨胀。 To give an example: 举个例子:

<text style="color: white; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; position: absolute; fill: white;" x="1288" y="252" zIndex="2">
<tspan style="font-weight: bold;" x="1288">
<text style="color: white; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; position: absolute; fill: white;" x="1288" y="452" zIndex="2">
<tspan style="font-weight: bold;" x="1288">

This represents just 2 objects in the chart and each time you can see the color, font, position and fill are added as an inline styles... 这只代表图表中的2个对象,每次可以看到颜色,字体,位置和填充都添加为内联样式...

Having not had too much exposure to SVG, is this a requirement? 没有太多暴露于SVG,这是一个要求吗? What I would like to be able to do would be to add a class to the text, say 'hc-txt' then I can set the color, font, position and fill in my CSS file. 我希望能够做的是在文本中添加一个类,比如'hc-txt'然后我可以设置颜色,字体,位置和填写我的CSS文件。

eg 例如

<text class="hc-txt" x="1288" y="252">
<tspan x="1288">
<text class="hc-txt" x="1288" y="452">
<tspan x="1288">

Having looked in the src file, I have been able to shorten the prefix from highcharts- to hc- which also helps tidy up the markup a little but changing the way in which these objects are created, am I being over ambitious? 查看了src文件后,我已经能够将前缀从highcharts缩短为hc-这也有助于整理标记,但改变了这些对象的创建方式,我是否过于雄心勃勃?

Thanks in advance, 提前致谢,

Will. 将。

Adding class attribute to the element should work - please check: 添加类属性应该工作 - 请检查:

http://www.w3.org/TR/SVG/styling.html#StylingWithCSS http://www.w3.org/TR/SVG/styling.html#StylingWithCSS

and specifically this one: 特别是这一个:

http://www.w3.org/TR/SVG/styling.html#ClassAttribute http://www.w3.org/TR/SVG/styling.html#ClassAttribute

Highcharts 5 introduces styled mode! Highcharts 5介绍了样式模式! you can now style the charts using css which will remove the need for all of the inline styles. 您现在可以使用css设置图表的样式,这将消除对所有内联样式的需要。 Style by CSS - highcharts.com CSS风格 - highcharts.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM