2017-05-07 114 views
-3

我应该使用什么库来创建图像中的图表?对不起,我发布这里,但我不知道在哪里发布。 enter image description here如何创建此类图表?我应该使用什么库?

+0

为什么不浏览到图表您添加的标签或相关标签,或者[搜索SO](http://stackoverflow.com/search?q=charts+library) – yezzz

+0

[JavaScript Chart Library]的可能重复(http://stackoverflow.com/questions/119969/javascript-chart-library) – yezzz

回答

1

我认为没有必要包括和学习一个大的lib。

我告诉你用帆布一点点PROTOTYP,从此建立一个功能:

var arcPos = degree => Math.PI*2/360*degree, 
calcLength = percent => 300 * (percent/100), 
percent =75, 
color = '#00f', 
oldValue = 73, 
vz='', 
canvas = document.getElementById('myCanvas'), 
context = canvas.getContext('2d'), 
radius = 70; 
with (context){ 
    beginPath(); 
    arc(canvas.width/2, canvas.height/2, radius, 
     arcPos(120),arcPos(60), false); 
    lineWidth = 15; 
    strokeStyle = '#ddd'; 
    lineCap = "round" 
    stroke(); 
    beginPath(); 
    arc(canvas.width/2, canvas.height/2, radius, arcPos(120), 
     arcPos(calcLength(percent) + 120), false); 
    strokeStyle = color; 
    stroke(); 
    font = "normal bold 50px sans-serif"; 
    textAlign = 'center'; 
    fillText(percent, 100, 100); 
    font = "normal bold 16px sans-serif"; 
    textAlign = 'center'; 
    vz=((percent - oldValue) > 0)?'+':''; 
    fillText(oldValue + ' (' + vz + (percent - oldValue) + '%)', 100, 130); 
    if ((percent - oldValue) > 0) { 
     beginPath(); 
     lineWidth = 3; 
     strokeStyle = '#f00'; 
     moveTo(100, 165);lineTo(100, 145);stroke(); 
     beginPath();moveTo(100, 145);lineTo(105, 150);stroke(); 
     moveTo(100, 145);lineTo(95, 150);stroke(); 
    } 
    if ((percent - oldValue) < 0) { 
     beginPath(); 
     lineWidth = 3; 
     strokeStyle = '#f00'; 
     moveTo(100, 165);lineTo(100, 145);stroke(); 
     beginPath();moveTo(100, 165);lineTo(105, 160);context.stroke(); 
     moveTo(100, 165);lineTo(95, 160);stroke(); 
    } 
} 

a liddle fiddle

这一套属性oldValue 73玩...

+0

谢谢!这是我第一次使用图表 – Nodos

1

对于一个简单的图表(只有甜甜圈),你可以使用chartjs

如果你想重新创建你发布的图像(甜甜圈,文本,%...),你应该去d3js,这有点棘手,但你可以做你想做的一切。

相关问题