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 6124083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:05:32+00:00 2026-05-23T16:05:32+00:00

I’d like to have both the values and the data categories on a graph.

  • 0

I’d like to have both the values and the data categories on a graph. This is a bar chart and I’d like to have the data values and a string printed in columns off to the left of the bar:

A 1 #

B 3 ###

I tried chaining a two add(pv.Label) calls onto my graph, but it seems to do nothing – the second label set is not added. Is this something that can even be done with protovis? any advice?

vis = new pv.Panel()
.def("j", -1)
.width(800)
.height(50)
.right(3);

vis.add(pv.Bar)
.data(wData)
.bottom(0)
.width(20)
.height(function(d) d[1] * 1.2)
.left(function() this.index * 27)
.fillStyle(function() vis.j() == this.index ? "orange" : "steelblue")
.add(pv.Label)  **// does nothing!!**
.bottom(0)
.textAlign("center")
.textStyle("white")
.text(function(d) d[0] )
.event("mouseover", function() vis.j(this.index))
.event("mouseout", function() vis.j(-1))
.anchor("top").add(pv.Label)
.visible(function() vis.j() >= 0)
.textStyle("white")
.text(function(d) d[1]);
vis.render();
  • 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-05-23T16:05:32+00:00Added an answer on May 23, 2026 at 4:05 pm

    I actually did see both labels when I tried this out. But there are a couple of things that could be fixed here. The key point is that when you’re chaining methods like this, when you add() a new mark, you change the context of the following method calls, e.g.:

    vis.add(pv.Bar)
        // this applies to the Bar
        .width(10)
      .add(pv.Label)
        // this applies to the label
        .top(5);
    

    There are a couple issues with this in your code:

    • Your event() handlers are attached to the Label, not to the Bar – unfortunately, Labels can’t receive events in Protovis.

    • Your second Label is attached to the first Label. While this actually seems to work somewhat, it’s better to avoid it – you really want it attached to the Bar.

    The easy way to deal with this is to only chain methods on a single mark. You can do this by assigning the parent mark to a variable, then using that variable several times for different child marks. You also have you first Label attached directly to the Bar, and not to an anchor – attaching it to an anchor will usually give you more predictable results.

    Updated code:

    // make a new variable to refer to the bars
    var bars = vis.add(pv.Bar)
        .data(wData)
        .bottom(0)
        .width(20)
        .height(function(d) d[1] * 1.2)
        .left(function() this.index * 27)
        .fillStyle(function() vis.j() == this.index ? "orange" : "steelblue")
        // you need to move the events up to apply 
        // to the bar - labels can't receive events, 
        // and the index will always be 0
        .event("mouseover", function() vis.j(this.index))
        .event("mouseout", function() vis.j(-1));
    
    // now add each label to the bars
    bars.anchor('bottom').add(pv.Label)
        .bottom(0)
        .textAlign("center")
        .textStyle("white")
        .text(function(d) d[0] );
    
    // and again
    bars.anchor("top").add(pv.Label)
        .visible(function() vis.j() >= 0)
        .textStyle("white")
        .text(function(d) d[1]);
    

    There’s a working version here: http://jsfiddle.net/nrabinowitz/ABmuq/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I want to count how many characters a certain string has in PHP, but

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.