D3.js nvd3-如何用特定的坐标在散点图上画一条线

D3.js nvd3-如何用特定的坐标在散点图上画一条线,d3.js,nvd3.js,D3.js,Nvd3.js,我用“scatterPlusLineChart”模型绘制了一个散点气泡图,它工作正常。但我需要用具体的点来画一条线。如果有人知道,请帮忙 var chart; nv.addGraph(function() { chart = nv.models.scatterPlusLineChart() .showDistX(true) .showDistY(true) .transitionDuration(

我用“scatterPlusLineChart”模型绘制了一个散点气泡图,它工作正常。但我需要用具体的点来画一条线。如果有人知道,请帮忙

var chart;
nv.addGraph(function() {
  chart = nv.models.scatterPlusLineChart()
                .showDistX(true)
                .showDistY(true)
                .transitionDuration(300)
                .color(d3.scale.category10().range());

  chart.xAxis.tickFormat(d3.format('.02f'))
  chart.yAxis.tickFormat(d3.format('.02f'))
  var graphData = [{key : 'Group1', 
                          values : [{x:1, y:5, shape : 'circle'}, {x:4, y:2, shape : 'circle'}]
                   },
                   {key : 'Group2', 
                          values : [{x:4, y:3, shape : 'circle'}, {x:1, y:6, shape : 'circle'}]
                   }
                   ]
  d3.select('#test1 svg')
      .datum(nv.log(graphData))
      .call(chart);

  nv.utils.windowResize(chart.update);

  chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });

  return chart;
});
以上是现有代码,以下是我的要求

画两条线

1) 通过(1,5)到(4,3)


2) 通过(4,2)到(1,6)

使用
slope
intercept
groups参数指定线条参数

例如:

var graphData = [{
        key: 'Group1',
        values: [{
            x: 1,
            y: 5
        }, {
            x: 4,
            y: 2
        }],
        intercept: 6,
        slope: -1
    }, {
        key : 'Group2',
        values : [{
            x: 4,
            y: 3
        }, {
            x: 1,
            y: 6
        }],
        intercept: 7,
        slope: -1
    }]

我让您使用来计算趋势线的斜率和截距。

您可以添加表示这些线的数据。@Lars Kotthoff请指定我不知道您的数据是什么样的,所以我不能告诉您:)