javascript 如何在flot中为条形图提供纯色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9311147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to give solid colors to bar charts in flot
提问by Coder_sLaY
I need to give solid colors to bar charts... I have followed this link Bar chart Example
我需要为条形图提供纯色...我已按照此链接 条形图示例
But i want to give solid colors and also i need to change colors myself... how to do it...
但我想给纯色,而且我需要自己改变颜色......怎么做......
回答by Ryley
First off, read the API.txt, it answers all your questions. Two things you need to do then. When you specify that you want bars, set fill: 1
, which tells flot to make the colors 100% opaque. To specify a colour per series, just add a color:'red'
to each data object.
首先,阅读API.txt,它回答你所有的问题。这时候你需要做两件事。当你指定你想要条形时, set fill: 1
,它告诉 flot 使颜色 100% 不透明。要为每个系列指定颜色,只需color:'red'
向每个数据对象添加一个。
So you end up with a data object like this:
所以你最终得到一个像这样的数据对象:
var data = [
{label: 'foo', color:'red', data: [[1,300], [2,300], [3,300], [4,300], [5,300]]},
{label: 'bar', color:'blue', data: [[1,800], [2,600], [3,400], [4,200], [5,0]]},
{label: 'baz', color:'yellow', data: [[1,100], [2,200], [3,300], [4,400], [5,500]]},
];
And flot options like this:
和浮动选项是这样的:
{
series: {
stack: 1,
bars: {
show: true,
barWidth: 0.6,
fill:1
}
}
}
See it in action here: http://jsfiddle.net/ryleyb/kKdxt/
在这里查看它的实际效果:http: //jsfiddle.net/ryleyb/kKdxt/