Web 如何在谷歌折线图中画出虚线?

Web 如何在谷歌折线图中画出虚线?,web,google-visualization,Web,Google Visualization,我正在尝试在我的网站中使用趋势线,并希望将其设为虚线,但lineDashStyle在趋势线选项下不起作用。是否可以将趋势线设为虚线?没有用于修改趋势线虚线样式的标准图表选项 但是,可以在图表的'ready'事件中手动更改图表 一旦找到,趋势线将由svg元素表示, 将属性笔划dasharray设置为所需的划线样式 path.setAttribute('stroke-dasharray', '5, 5'); (MDN web文档-->) 请参阅以下工作片段, 趋势线的颜色用于查找元素 使用图表选项

我正在尝试在我的网站中使用趋势线,并希望将其设为虚线,但lineDashStyle在趋势线选项下不起作用。是否可以将趋势线设为虚线?

没有用于修改趋势线虚线样式的标准图表选项
但是,可以在图表的
'ready'
事件中手动更改图表

一旦找到,趋势线将由svg
元素表示,
将属性
笔划dasharray
设置为所需的划线样式

path.setAttribute('stroke-dasharray', '5, 5');
(MDN web文档-->)

请参阅以下工作片段,
趋势线的颜色用于查找
元素
使用图表选项设置颜色-->
趋势线。n.color

其中
n
是趋势线的系列指数

google.charts.load('current'{
软件包:['corechart']
}).然后(函数(){
var data=google.visualization.arrayToDataTable([
[“日期”,“值”],
[新日期(2017年2月10日),100],
[新日期(2017年2月21日),150],
[新日期(2017年2月28日),160],
[新日期(2017年3月7日),150],
[新日期(2017年3月14日),125],
[新日期(2017年3月23日),130],
[新日期(2017年3月31日),135],
[新日期(2017年4月7日),140],
[新日期(2017年4月26日),145],
[新日期(2017年5月3日),130],
[新日期(2017年5月10日),150],
[新日期(2017年5月17日),165],
[新日期(2017年5月25日),175],
[新日期(2017年6月5日),180],
[新日期(2017年6月12日)100]
]);
变量选项={
图表区:{
底图:48,
高度:“100%”,
左:48,
右:16,
前48名,
宽度:“100%”
},
颜色:['#c3d5bc'],
哈克斯:{
格式:“M/d/yy”,
倾斜文字:“真的”
},
高度:“100%”,
图例:{
对齐:“开始”,
位置:'顶部'
},
趋势线:{
0: {
颜色:“#344f35”,
类型:“线性”
}
},
宽度:“100%”
};
var container=document.getElementById('chart_div');
var chart=新的google.visualization.AreaChart(容器);
//将趋势线更改为虚线
google.visualization.events.addListener(图表'ready',函数(){
var pathElements=container.getElementsByTagName('path');
Array.prototype.forEach.call(路径元素,函数(路径)){
if(path.getAttribute('stroke')==options.trendlines[0].color){
setAttribute('stroke-dasharray','5,5');
}
});
});
图表绘制(数据、选项);
});

可以使用css,按颜色搜索:

google-chart path[stroke='#f2994a'] {
  stroke-dasharray: 6, 6;
}