Javascript 图中的动态颜色
我尝试使用jquery动态加载颜色 这是有效的:Javascript 图中的动态颜色,javascript,jquery,morris.js,Javascript,Jquery,Morris.js,我尝试使用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}, {la
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) {
Morris.Donut({
element: 'donut-example',
colors : colors,
data : [
{label: "Download Sales", value: 12},
{label: "In-Store Sales", value: 30},
{label: "Mail-Order Sales", value: 20}
]
});
}
graphDonut( ['#9CC4E4', '#3A89C9', '#F26C4F'] );
或
我想你需要换个新的
var colors_array = '["' + value + '"]';
与
它给了我这个输出:
["#9CC4E4", "#3A89C9", "#F26C4F"]
希望这有帮助。替换下面的代码
Morris.Donut({
元素:“甜甜圈示例”,
颜色:[“9CC4E4”、“3A89C9”、“F26C4F”],
数据:[
{标签:“下载销售”,值:12},
{标签:“店内销售”,价值:30},
{标签:“邮购销售”,价值:20}
]
});代码>请尝试以下操作:
<script>
new Morris.Donut({
element: 'donut-example',
data: [
{label: "Serie 1", value: 12},
{label: "Serie 2", value: 30},
{label: "Serie 3", value: 20},
{label: "Serie 3", value: 20}
],
colors: ['#a6d000', '#0070e7', '#e700b5', '#ffab17'],
xkey: 'y',
ykeys: ['vaue']
});
</script>
新莫里斯甜甜圈({
元素:“甜甜圈示例”,
数据:[
{标签:“系列1”,值:12},
{标签:“系列2”,值:30},
{标签:“系列3”,值:20},
{标签:“系列3”,值:20}
],
颜色:[“a6d000”、“0070e7”、“e700b5”、“ffab17”],
xkey:'y',
ykeys:['vaue']
});
var colors_array = value.split("|");
["#9CC4E4", "#3A89C9", "#F26C4F"]
<script>
new Morris.Donut({
element: 'donut-example',
data: [
{label: "Serie 1", value: 12},
{label: "Serie 2", value: 30},
{label: "Serie 3", value: 20},
{label: "Serie 3", value: 20}
],
colors: ['#a6d000', '#0070e7', '#e700b5', '#ffab17'],
xkey: 'y',
ykeys: ['vaue']
});
</script>