【问题标题】:Hide 0 valued stack bar in stacked bar chart of JQPlot在 JQPlot 的堆叠条形图中隐藏 0 值的堆叠条
【发布时间】:2023-03-25 09:32:01
【问题描述】:

我正在使用 JQPlot 生成堆积条形图,其中很少有堆栈可能具有 O 值。我的要求是我不想显示该统计数据的 O 级别,其值为 0。请让我知道我应该使用什么 JQPLOT API

我的代码:

function getChart2()
    {
        var s1 = [32.40, 80.00, 80.00, 16.94, 72.12, 78.10, 80.00];
        var s2 = [0.00, 12.34, 3.68, 0.00, 0.00, 0.00, 15.67];

        var ticks = ['A', 'B', 'C', 'D','E','F','G'];
  plot3 = $.jqplot('chartdiv', [s1, s2], {
    // Tell the plot to stack the bars.
    stackSeries: true,
    captureRightClick: true,
    seriesDefaults:{
      renderer:$.jqplot.BarRenderer,
      rendererOptions: {
          fillToZero: true, barDirection: 'horizontal'
      },
      pointLabels: {show: true}
    },
    axes: {
      xaxis: {
           pad: 1.05,
           tickOptions: {formatString: '%.2f %'},
           formatter:function() {if(this.x > 0.00) {
      return this.x;
    } }
      },
      yaxis: {
         renderer: $.jqplot.CategoryAxisRenderer,
         ticks: ticks
      }
    },
    legend: {
      show: true,
      location: 'e',
      placement: 'outside'
    }     
  });
    }

【问题讨论】:

  • 现场直播JS Fiddle 或类似的演示会非常有帮助。

标签: javascript jqplot


【解决方案1】:

我为此使用了 hideZeros:true 选项,现在它正在工作。

pointLabels: {show: true,hideZeros:true,labelsFromSeries:true,xpadding: 6}

【讨论】:

    【解决方案2】:

    大家好,感谢您帮助我 我设法解决了我的问题

    我用它来解决我的问题:

    stackSeries:真, 捕获右键单击:真, 系列默认值:{ 渲染器:$.jqplot.BarRenderer, 渲染器选项:{ highlightMouseDown:真, 条宽:40, },

        pointLabels: {
            show: true,
            formatString: '%s',
            formatter: function val(x, y) {
    
                //my Solution
                if (y != 0)
    
                    return y.toString().toHHMMSS();
            },
        },
    
    },
    

    【讨论】:

      猜你喜欢
      • 2012-05-11
      • 1970-01-01
      • 2023-01-31
      • 2014-06-18
      • 2023-01-21
      • 2021-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多