如何在nvd3中排序栏? [英] How to sort bar in nvd3?

查看:120
本文介绍了如何在nvd3中排序栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用nvd3 multibar图表。它的工作正常。这里我需要根据值(我的意思是以升序/降序)的方式排序。是否有任何内置函数可用于在nvd3中排序。或者如何实现排序的东西。

I am using nvd3 multibar chart in my application. Its working fine. Here i need to sort the bars based on the values(I mean in ascending/descend manner). Is there any inbuilt function available for sorting in nvd3. Or how can I achieve the sorting thing.

nv.addGraph(function() {

  var chart;
  chart = nv.models.multiBarChart()
    .margin({bottom: 100})
    .transitionDuration(300);

  chart.options( {delay: 1200});

  chart.multibar
    .hideable(false);

  chart.xAxis
      //.axisLabel("Modules")
      .rotateLabels(45);

  chart.yAxis
   .tickFormat(function(d) { return d + "%"; });


  d3.select('#' + "barChart" + ' svg')
      .datum(data)
     .call(chart);

  nv.utils.windowResize(chart.update);

  chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });

  return chart;
});


推荐答案

你把它传递给图表?这是我做了1行,它的工作原理像一个魅力。它是更清洁,更容易有复杂的排序取决于数据。

Isn't it easier to just sort the array before you pass it to the chart? That is what I did with 1 line and it works like a charm. It is way cleaner and easier to have complex sorting depending on the data.

这篇关于如何在nvd3中排序栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆