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

标签 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
    }},

  ]
}
  });
});

最佳答案

我通过如下修改函数完成了上述工作

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
    }   
}

我已将设置的颜色值传递给上述方法...谢谢大家

关于jquery - 如果生成图表时值低于 2.5,则条形图的颜色应为红色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13852594/

相关文章:

javascript - 如何在 Grails 中嵌入 jqPlot?有什么特殊标签吗?

javascript - 如何使用 jQPlot 在 yaxis = 0 处画一条线?

jquery - Ajax 设置问题

javascript - 遍历 div 以查找每个类的所有元素不起作用

php - 为每个序列化 ID 和 PHP

javascript - 在 IE7/8 中将 excanvas 元素保存为图像

javascript - 在javascript中将表格html转换为Excel

javascript - 如何处理外部 api JSON 而不是 JSONP

jquery - jqplot : How to change axes ticks formatString after zooming

javascript - 将 jqplot 图表转换为图像