如果在生成图形时该值低于2.5,则条形图的颜色应为红色

时间:2012-12-13 03:44:07

标签: jquery jqplot

以下是我的代码......

在下面的示例中,有2个条形图,其值低于目标值2.5 ......需要以红色显示的条形图。

$(document).ready(function(){
  var line1 = [['Content Of The Training', 2.2], ['Relavance Of Training To The Work Place', 3.5], ['Phase Of The Training', 3.2], 
  ['Session Met The Objectives Stated', 3.4], [' The Session Met My Exceptations', 3], 
  ['Overall Ratining On the Training', 2.1]];

  var plot1 = $.jqplot('graph1', [line1], {
    title: 'Rating On Training',
    series:[{renderer:$.jqplot.BarRenderer}],
    axesDefaults: {
        tickRenderer: $.jqplot.CanvasAxisTickRenderer ,
        tickOptions: {
        fontFamily: 'Calibri',
          angle: -30,
          fontSize: '10pt'
        }
    },

axes: {
  xaxis: {
    renderer: $.jqplot.CategoryAxisRenderer
  }
},
    canvasOverlay: {
  show: true,
  objects: [
    {horizontalLine: {
      name: 'pebbles',
      y: 2.5,
      lineWidth: 2,
      color: 'rgb(255, 0, 0)',
      shadow: true,
      lineCap: 'butt',
      xOffset: 0
    }},

  ]
}
  });
});

1 个答案:

答案 0 :(得分:2)

我已完成以上修改功能如下

var barColorSetter = function(indexVal, ratingValue, limit)
{
    if(ratingValue<limit)
    {
        myBarColors[indexVal]="#750000";//maroon
    }
    else if(ratingValue == limit)
    {`enter code here`
        //myBarColors[indexVal]="#7399D2";//Blue
                myBarColors[indexVal]="#FF7E00";//traffic Yellow(amber color)
    }
    else
    {
        myBarColors[indexVal]="#135F0E";//green
    }   
}

我已经将设定的颜色值传递给上面的方法....谢谢大家