您可以使用ChartJS的甜甜圈圖表。只要確保將甜甜圈分成12個相同的數據組(在我的例子中,我將對所有12個數據點使用1)。這將使他們都相同的大小。然後你可以單獨控制它們的顏色,並在之後更新圖表。
https://jsfiddle.net/8t8tmc0q/
必要的HTML:
<canvas id="myChart" width="400" height="400"></canvas>
和Javascript:
Chart.defaults.global.legend.display = false;
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['1','2','3','4','5','6','7','8','9','10','11','12'],
datasets: [{
data: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
backgroundColor: [
'white',
'white',
'white',
'white',
'white',
'white',
'white',
'white',
'white',
'white',
'white',
'white'
],
borderColor: 'black',
borderWidth: 1
}]
}
});
然後,更新的顏色,你只需指定要更新哪些部分,並使用myChart.update()
函數繪製變化:
myChart.data.datasets[0].backgroundColor[5] = 'red'
myChart.update();
已經有關於與計算器http://stackoverflow.com/questions/14184494/segments-in-a-circle-using-css3 – kkreft
@kkreft的解決方案我沒有看到你的問題一個線程,但我米不試圖做切片 - 而是我想控制的弧線 – blazerix
http://stackoverflow.com/questions/14383088/how-to-create-a-certain-configuration-given-below-in-html 我也看着上面的問題,但沒有解決方案。那個用戶和我一樣有問題 – blazerix