简体   繁体   English

独特的颜色为flot条形图

[英]Unique colors for flot bar chart

I want to create a flot bar chart that will display true and false figures, like my example below. 我想创建一个显示真假数字的flot条形图,如下面的例子。 I want the true bar to be green and the false one to be red. 我希望真正的酒吧是绿色的,而假的酒吧是红色的。 I've tried using the colors array but it doesn't work properly. 我尝试使用colors数组,但它无法正常工作。

My current code: 我目前的代码:

var options3 = {grid: {hoverable: true},series: {bars: {show: true,barWidth: 0.6,align: "center"}},yaxis: {min:0,tickSize: 1},xaxis: {mode: "categories",ticks: [ [0, 'True'], [1, 'False'] ],tickLength: 0},tooltip: true,tooltipOpts: {content: '%y Votes', defaultTheme: false}, colors: [ "#FF0000", "#00FF00"]};
var data3 = [ [0, 3], [1, 9] ];
$(document).ready(function() {
    $.plot('#graph3', [data3], options3);
});

Example: http://joshblease.co.uk/Maths/Admin/chart.php#graph3 示例: http//joshblease.co.uk/Maths/Admin/chart.php#graph3

The problem is that you have only one data series, which is assigned the first color in your array (red). 问题是您只有一个数据系列,它被分配了数组中的第一种颜色(红色)。 You will get the result you want if you replace 如果更换,您将获得所需的结果

var data3 = [ [0, 3], [1, 9] ];

with

var data3 = [
    [[0, 3]],
    [[1, 9]]
];

Then use data3 in the plot instead of [data3] . 然后在图中使用data3而不是[data3] See the jsFiddle . 看到jsFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM