我嘗試用jquery動態加載顏色。圖中的動態顏色
這是工作:
var colors_array= ["#9CC4E4", "#3A89C9", "#F26C4F"];
Morris.Donut({
element: 'donut-example',
colors: colors_array,
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
期望的結果(不工作):
function graphDonut(colors) {
var value = colors;
value = value.replace(/\|/g,'", "');
var colors_array = '["' + value + '"]';
Morris.Donut({
element: 'donut-example',
colors: colors_array,
data: [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
}
graphDonut("#9CC4E4|#3A89C9|#F26C4F");