English 中文(简体)
In d3 chart the line look like it would go to 0 - how to avoid that?
原标题:
  • 时间:2023-07-02 02:47:00
  •  标签:
  • d3.js

The curve in the d3 chart looks like it would be going to 0, (see attached picture). Is there a way to prevent that from happening? I want it to stop at the last value of the y axis.

enter image description here

// Draw graph line
g.append( path )
  .datum(prices)
  .attr( d , area(prices))
  .attr( class ,  area-bg )
  .attr( fill ,  url(#lightGradient) )
  .attr( stroke ,  #15AA27 )
  .attr( stroke-width ,  1 )
  .style( opacity ,  0.6 )

...

// For today s day indicate current pricing
if (this.day == Today) {

  // Draw the current pricing line
  g.append( line )
    .attr( id ,  limit )
    .attr( x1 , innerWidth * this.markerY)
    .attr( y1 , innerHeight)
    .attr( x2 , innerWidth * this.markerY)
    .attr( y2 , 1)
    .attr( stroke ,  #484848 )
    .attr( stroke-dasharray , 2.5)

....

  // Draw the current pricing label
  g.append( text )
    .attr( fill ,  #484848 )
    .append( tspan )
    .attr( x , innerWidth * this.markerY + this.labelOffsetY)
    .attr( dy ,  10px )
    .text("Current pricing")
    .attr("font-size","10px");

....

  // Draw the current pricing label
  g.append( text )
    .attr( fill ,  #484848 )
    .append( tspan )
    .attr( x , innerWidth * this.markerY + this.labelOffsetY)
    .attr( dy ,  22px )
    .text(this.currentValue + "/kWh")
    .attr("font-size","10px");
}

....

// Draw the y-lines
g.select( .grid )
  .style( stroke ,  #79828F )
  .style( stroke-width ,  0.5 )

// Draw the box around the graph
g.select( .domain )
  .style( stroke ,  #fff )
  .style( stroke-width ,  0 )
问题回答

暂无回答




相关问题
Embedding tweets in D3 tooltip

I m trying to build a custom D3 tooltip that displays a tweet widget using the copy/paste code from publish.twitter.com. I m setting up plots using plotly in R and would like a tweet widget to be ...

d3.js and document.onReady

I m just getting started with d3.js and there is one detail which is completely eluding me: how do I have my code execute only after the DOM is ready to receive input? I could, of course, use ...

Using nested data with D3.js

I am trying to display a beautiful line graph using D3. The problem I have is with the format of the data. I have the following data (as an example): var data = [ { label: "name", ...

Implementing zoom buttons using d3

I am trying to develop a graph visualization webpage using d3, and I need to provide basic zoom and pan functionality over the graph. I saw the d3.behaviour.js file to see how the zoom functionality ...

Protovis vs D3.js

TLDR: Does anyone have experience of both protovis & D3.js to illuminate the differences between the two? I ve been playing with protovis for the last 2 weeks and it s been great so far. Except ...

热门标签