So here's my setup...
import { D3Service, D3, Selection } from 'd3-ng2-service';
interface ChartData {
q: number,
p: number
}
export class GraphComponent implements OnInit{
private d3;
private x1;
private y;
constructor(element: ElementRef, d3Service: D3Service) {
this.d3 = d3Service.getD3();
let d3 = this.d3;
this.y = d3.scaleLinear()
.domain([0,100])
.range([330, 20])
;
this.x1 = d3.scaleLinear()
.range([0, 100])
;
}
render() {
let y = this.y;
let x1 = this.x1;
let data = [{p:1,q:1}, {p:0.5,q:2}]
var line = d3.line()
.x((d: ChartData) => {return x1(d.q);})
.y((d: ChartData) => {return y(d.p);});
svg.append("path")
.data(data)
.attr("class", "line")
.attr("d", line);
}
}
Encountered an issue when trying to define the x value using .x(d: ChartData), showing the following error message:
Error: Argument of type '(d: ChartData) => any' is not compatible with parameter of type '(d: [number, number], index: number, data: [number, number][]) => number'. Types of parameters 'd' and 'd' are mismatched. The property 'q' is missing in type '[number, number]'.
After referring to the d3 documentation, it seems injecting data into line() via line(data) might be the solution for custom data utilization.
var line = d3.line(data)
.x((d: ChartData) => {return x1(d.q);})
.y((d: ChartData) => {return y(d.p);});
However, this resulted in a new error...
Error: Supplied parameters do not match any signature of call target at file.ts:259.
Despite the guidance from d3, I seem to have missed something. Any idea what could be going wrong?