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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:03:34+00:00 2026-06-07T17:03:34+00:00

I have a line chart and the full array of data is attached to

  • 0

I have a line chart and the full array of data is attached to the line. I want to change from using the value column to the pct (percent) column in the data. Is there a way of doing this in place, ie. using the values already in the DOM without passing it a new set of data?

as far as I’ve got – http://bl.ocks.org/3099307

var width = 700,   // width of svg
        height = 400,  // height of svg
        padding = 100; // space around the chart, not including labels

var data=[{"date":new Date(2012,0,1), "value": 3, 'pct': 55},
    {"date":new Date(2012,0,3), "value": 2, "pct": 30      },
    {"date":new Date(2012,0,12), "value": 33, "pct": 10},
    {"date":new Date(2012,0,21), "value": 13, "pct": 29},
    {"date":new Date(2012,0,30), "value": 23, "pct": 22}];


var x_domain = d3.extent(data, function(d) {
            return d.date; }),
        y_domain = d3.extent(data, function(d) { return d.value; });

// define the y scale  (vertical)
var yScale = d3.scale.linear()
        .domain(y_domain)
        .range([height - padding, padding]);   // map these top and bottom of the chart


var xScale =  d3.time.scale()
        .domain(x_domain)
        .range([padding, width - padding]);   // map these sides of the chart, in this case 100 and 600

// define the y axis
var yAxis = d3.svg.axis()
        .orient("left")
        .scale(yScale);

// define the x axis
var xAxis = d3.svg.axis()
        .orient("bottom")
        .scale(xScale);



// create the svg

var div = d3.select("body");

div.select("svg").remove();


var vis = div.append("svg")
        .attr("width", width)
        .attr("height", height)
        .attr("transform", "translate(" + padding + "," + padding + ")");






// draw y axis with labels and move in from the size by the amount of padding
vis.append("g")
        .attr("class", "axis yaxis")
        .attr("transform", "translate("+padding+",0)")
        .call(yAxis);

// draw x axis with labels and move to the bottom of the chart area
vis.append("g")
        .attr("class", "axis")
        .attr("transform", "translate(0," + (height - padding) + ")")
        .call(xAxis);



// DRAW LINES

var line = d3.svg.line()
        .x(function(d) {
            return xScale(d.date); })
        .y(function(d) {
            return yScale(d.value); })
        .interpolate("basis");

vis.selectAll(".lines")
        .data([data])
        .enter()
        .append("svg:path")
        .attr("d", line)
        .attr("class", "lines");


function rescale() {
    // change the y axis to show percentage

    yScale.domain([0,100])  // redraw as percentage outstanding
    vis.select(".yaxis")
            .transition().duration(1500).ease("sin-in-out")  // https://github.com/mbostock/d3/wiki/Transitions#wiki-d3_ease
            .call(yAxis);

What happens here?

    // now redraw the line to use pct
    line.y(function(d) {
                return yScale(d.pct); });

     vis.selectAll("lines")
                .transition()
                .duration(500)
                .ease("linear");
}
  • 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-07T17:03:35+00:00Added an answer on June 7, 2026 at 5:03 pm

    Your data is already joined, so you just need to update your selection:

    var yPctScale = d3.scale.linear()
        .domain([0, 100])
        .range([height - padding, padding]);
    
    var pct_line =  d3.svg.line()
        .x(function(d) {
            return xScale(d.date); })
        .y(function(d) {
            return yPctScale(d.pct); })
        .interpolate("basis");
    
    vis.selectAll(".lines")
        .transition().duration(1500).ease("sin-in-out")
        .attr("d", pct_line);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have create simple line chart using Android Plot library. what i want to
I have created a line chart using Reporting Services that charts the number of
I am using below URL to show line chart but one thing I have
I'm using Visifire. I have plotted about 500+ points on a line chart. However,
So I have a google line chart visualization with a data set that has
I have a line chart that sometimes contains a number of data points. I
I have a line chart that is updated every so and so seconds, similar
For example we have this line chart at Google Code API there is a
I have a simple JSF line chart that uses PrimeFaces (via jqPlot) library: <p:lineChart
I have made a simple Line Chart: Which is showing 4 grid-lines at points

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.