Javascript 带有动画图像SVG文件和图表JS的自定义pointStyle
我使用ChartJs绘制图表并尝试更改pointStyle。我想使用svg格式的动画来定制pointStyle,但它在图表上没有运动效果。我不知道是否可以在canvs上绘制svg图像,请帮助我。非常感谢你 这是我的代码:[LinkCodepen][1]Javascript 带有动画图像SVG文件和图表JS的自定义pointStyle,javascript,svg,charts,gif,Javascript,Svg,Charts,Gif,我使用ChartJs绘制图表并尝试更改pointStyle。我想使用svg格式的动画来定制pointStyle,但它在图表上没有运动效果。我不知道是否可以在canvs上绘制svg图像,请帮助我。非常感谢你 这是我的代码:[LinkCodepen][1] [1]: https://codepen.io/vungho/project/editor/XwKwGx/ <!DOCTYPE html> <html> <head> <title>Chart J
[1]: https://codepen.io/vungho/project/editor/XwKwGx/
<!DOCTYPE html>
<html>
<head>
<title>Chart JS</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
</head>
<body>
<img src="ripple.svg">
<div style="width:75%;">
<canvas id="canvas"></canvas>
</div>
<br>
<br>
<script>
var myImage = new Image();
myImage.src = "ripple.svg"
var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var config = {
type: 'line',
data: {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
pointStyle : [myImage, myImage, '', '', '', '', myImage, myImage],
data: [
20, 36, 46, 66, 87, 45, 49
],
fill: false,
}, {
label: "My Second dataset",
fill: false,
backgroundColor: 'rgb(54, 162, 235)',
borderColor:'rgb(54, 162, 235)',
pointStyle : ['', myImage, myImage, '', '', myImage, '', myImage],
data: [
45, 56, 65, 78, 54, 32, 69
],
}
]
},
options: {
responsive: true,
title:{
display:true,
text:'Chart.js Line Chart'
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
}]
}
}
};
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
};
</script>
</body>
</html>
[1]:https://codepen.io/vungho/project/editor/XwKwGx/
图表JS
var myImage=新图像();
myImage.src=“ripple.svg”
风险值月份=[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”];
变量配置={
键入:“行”,
数据:{
标签:[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”],
数据集:[{
标签:“我的第一个数据集”,
背景颜色:“rgb(255,99,132)”,
边框颜色:“rgb(255,99,132)”,
pointStyle:[我的图像,我的图像,','','',我的图像,我的图像],
数据:[
20, 36, 46, 66, 87, 45, 49
],
填充:假,
}, {
标签:“我的第二个数据集”,
填充:假,
背景颜色:“rgb(54162235)”,
边框颜色:'rgb(54162235)',
点样式:['',我的图像,我的图像,'','',我的图像,'',我的图像],
数据:[
45, 56, 65, 78, 54, 32, 69
],
}
]
},
选项:{
回答:是的,
标题:{
显示:对,
文本:“Chart.js折线图”
},
工具提示:{
模式:“索引”,
交集:错,
},
悬停:{
模式:“最近的”,
交集:对
},
比例:{
xAxes:[{
显示:对,
scaleLabel:{
显示:对,
标签串:“月”
}
}],
雅克斯:[{
显示:对,
scaleLabel:{
显示:对,
标签字符串:“值”
}
}]
}
}
};
window.onload=函数(){
var ctx=document.getElementById(“画布”).getContext(“2d”);
window.myLine=新图表(ctx,配置);
};
ripple.svg是:
请将代码包含在问题本身中,不要只是链接到小提琴,并将其用作欺骗用户的“代码”system@AlonEitan,对不起,我已更新了代码