Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8878763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:47:30+00:00 2026-06-14T19:47:30+00:00

I am trying to use nvd3 to create a vertical stacked bar chart. I

  • 0

I am trying to use nvd3 to create a vertical stacked bar chart. I will be using discrete data values, as opposed to randomly generated values as the example on their website.

I have tried to play around with the live code example of the Group / Stacked Bar Chart and put in JSON data containing my own values. What I tried to do was take the JSON data from the horizontal bar chart and put it in as the data for the vertical bar chart.

This is the data I used on the live code example in place of the data in the Group / Stacked Bar Chart:

[
  {
    "key": "Series1",
    "color": "#d62728",
    "values": [
      { 
        "label" : "Group A" ,
        "value" : -1.8746444827653
      } , 
      { 
        "label" : "Group B" ,
        "value" : -8.0961543492239
      } , 
      { 
        "label" : "Group C" ,
        "value" : -0.57072943117674
      } , 
      { 
        "label" : "Group D" ,
        "value" : -2.4174010336624
      } , 
      {
        "label" : "Group E" ,
        "value" : -0.72009071426284
      } , 
      { 
        "label" : "Group F" ,
        "value" : -0.77154485523777
      } , 
      { 
        "label" : "Group G" ,
        "value" : -0.90152097798131
      } , 
      {
        "label" : "Group H" ,
        "value" : -0.91445417330854
      } , 
      { 
        "label" : "Group I" ,
        "value" : -0.055746319141851
      }
    ]
  },
  {
    "key": "Series2",
    "color": "#1f77b4",
    "values": [
      { 
        "label" : "Group A" ,
        "value" : 25.307646510375
      } , 
      { 
        "label" : "Group B" ,
        "value" : 16.756779544553
      } , 
      { 
        "label" : "Group C" ,
        "value" : 18.451534877007
      } , 
      { 
        "label" : "Group D" ,
        "value" : 8.6142352811805
      } , 
      {
        "label" : "Group E" ,
        "value" : 7.8082472075876
      } , 
      { 
        "label" : "Group F" ,
        "value" : 5.259101026956
      } , 
      { 
        "label" : "Group G" ,
        "value" : 0.30947953487127
      } , 
      { 
        "label" : "Group H" ,
        "value" : 0
      } , 
      { 
        "label" : "Group I" ,
        "value" : 0 
      }
    ]
  }
]

I replaced the function call to data() in the javascript to data:

nv.addGraph(function() {
    var chart = nv.models.multiBarChart();

    chart.xAxis
        .tickFormat(d3.format(',f'));

    chart.yAxis
        .tickFormat(d3.format(',.1f'));

    d3.select('#chart svg')
        .datum(data)
      .transition().duration(500).call(chart);

    nv.utils.windowResize(chart.update);

    return chart;
});

The graph properly labels my series but does not show the bars. Can this graph not take this type of data? I got my data working with the horizontal bars, but I would like to use vertical bars if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:47:31+00:00Added an answer on June 14, 2026 at 7:47 pm

    The group/stacked bar chart (the multiBarChart model) is used with x and y attributes, where y is the height of the bar and x is the label and may be some number or a text.

    Unfortunately there isn’t much documentation on the exact data format and all examples I found use some confusing functions to generate data. So here’s an example I got working using mixed numeric and text labels:

    var chart = nv.models.multiBarChart();
    d3.select('#chart svg').datum([
      {
        key: "S1",
        color: "#51A351",
        values:
        [      
          { x : "A", y : 40 },
          { x : "B", y : 30 },
          { x : 5,   y : 20 }  
        ]
      },
      {
        key: "S2",
        color: "#BD362F",
        values:
        [      
          { x : "A", y : 60 },
          { x : "B", y : 50 },
          { x : 5,   y : 70 } 
        ]
      }
    ]).transition().duration(500).call(chart);
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.1/nv.d3.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.1/nv.d3.min.css">
    
    <div id="chart" style="height: 200px;"><svg></svg></div>

    group/stacked bar chart


    Now there are two issues with your code:

    1. You need to remove the tickFormat for axis you intend to label with texts.
      The tickFormat function sets a number format for the axis’ labels. It will only work if the label can be converted to a number and would result in NaN in your case.

    2. You need either to rename the label and value attributes to x and y or you need to create functions to provide those values:

      var chart = nv.models.multiBarChart();
      
      chart.x(function(d) { return d.label; });
      chart.y(function(d) { return d.value; });
      
      d3.select('#chart svg')
        .datum( /* your data */ )
        .transition().duration(500).call(chart); 
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone know how to create a cvCreateStructuringElementEx using a image? I'm trying use opencv.cv.cvCreateStructuringElementEx()
I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
Trying to use the http://www.dinnermint.org/css/creating-triangles-in-css/ method to create an arrow _________________ \ \ \
I was trying use svn to find a checkin using svn log, but it
I'm trying use make a div's background transparent using a mixture of CSS3 rgba()
I am trying use a from a multi-dimensional array that I create in another
I'm trying use epoch time dates in my series data. The array looks like
I'm trying to create a script that will delete all user properties for a
Hi I'm trying use a mixin to define some method using define_method. I would
i'm trying use facebook API to upload photo in my fan page. I downloaded

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.