D3线长调整

时间:2019-04-19 13:07:18

标签: d3.js

是否有一种简单的方法来限制D3中的线的长度,但保持其渐变。例如,在我的图表中,用户可以增加线条的坡度,但我希望它剪切掉Y轴上超出10的部分-有关详细信息,请参见图片

 var dataObject = {
 supplyElasticityZeroY :[0,1,2,3,4,5,6,7,8,9,10],
 supplyEaslticityZeroX : [0,1,2,3,4,5,6,7,8,9,10],
 supplyElasticityMinus1Y : [0,2,4,6,8,10],
 supplyElasticityMinus1X : [1,2,3,4,5,6,7,8,9,10],
 supplyElasticityMinus2Y : [0,4,8,12],
 supplyElasticityMinus2X : [2,3,4,5]
 }


var supplyElasticityLine = d3.line()
.x(function(d,i){
 switch(eosPosition){
  case -1: return   xScale(dataObject.supplyElasticityMinus1X[i]);
  case -2: return xScale(dataObject.supplyElasticityMinus2X[i]);
}})

.y(function(d,i){
   switch(eosPosition){
   case -1: return    yScale(dataObject.supplyElasticityMinus1Y[i]);
   case -2: return yScale(dataObject.supplyElasticityMinus2Y[i]);
 }});

enter image description here

0 个答案:

没有答案