Adds a lollipop chart
This commit is contained in:
parent
739707dd39
commit
a9bfc0dd47
|
@ -232,8 +232,8 @@ export class CdfChartD3 {
|
|||
.y0(this.calc.chartHeight);
|
||||
|
||||
// Add axis.
|
||||
this.chart.createObject({ tag: 'g', selector: 'axis' })
|
||||
.attr('transform', 'translate(' + 0 + ',' + this.calc.chartHeight + ')')
|
||||
this.chart.createObject({ tag: 'g', selector: 'xAxis' })
|
||||
.attr('transform', 'translate(0,' + this.calc.chartHeight + ')')
|
||||
.call(this.xAxis);
|
||||
|
||||
// Draw area.
|
||||
|
@ -303,52 +303,50 @@ export class CdfChartD3 {
|
|||
// Lollipops
|
||||
{
|
||||
const data = [
|
||||
{ Country: "United States", Value: "12394" },
|
||||
{ Country: "Ry", Value: "1000" },
|
||||
{ Country: "Dy", Value: "5000" },
|
||||
{x: 3, y: 10},
|
||||
{x: 5, y: 30},
|
||||
{x: 7.5, y: 50},
|
||||
];
|
||||
const xs = [3, 5, 7.5];
|
||||
|
||||
// X axis
|
||||
const x = d3.scaleBand()
|
||||
.range([0, this.calc.chartWidth])
|
||||
.domain(data.map(function (d) {
|
||||
return d.Country;
|
||||
}))
|
||||
.domain(xs)
|
||||
.padding(1);
|
||||
|
||||
this.svg.append("g")
|
||||
this.chart.append("g")
|
||||
.attr("transform", "translate(0," + this.calc.chartHeight + ")")
|
||||
.call(d3.axisBottom(x))
|
||||
.selectAll("text")
|
||||
.attr("transform", "translate(-10,0)rotate(-45)")
|
||||
.style("text-anchor", "end");
|
||||
.selectAll("text");
|
||||
|
||||
// Add Y axis
|
||||
const y = d3.scaleLinear()
|
||||
.domain([0, 13000])
|
||||
.domain([0, 50])
|
||||
.range([this.calc.chartHeight, 0]);
|
||||
|
||||
this.svg.append("g")
|
||||
this.chart.append("g")
|
||||
.attr("transform", "translate(" + this.calc.chartWidth + ",0)")
|
||||
.call(d3.axisLeft(y));
|
||||
|
||||
// Lines
|
||||
this.svg.selectAll("lollipops-line")
|
||||
this.chart.selectAll("lollipops-line")
|
||||
.data(data)
|
||||
.enter()
|
||||
.append("line")
|
||||
.attr("x1", d => x(d.Country))
|
||||
.attr("x2", d => x(d.Country))
|
||||
.attr("y1", d => y(d.Value))
|
||||
.attr("x1", d => x(d.x))
|
||||
.attr("x2", d => x(d.x))
|
||||
.attr("y1", d => y(d.y))
|
||||
.attr("y2", y(0))
|
||||
.attr("stroke", "red");
|
||||
|
||||
// Circles
|
||||
this.svg.selectAll("lollipops-circle")
|
||||
this.chart.selectAll("lollipops-circle")
|
||||
.data(data)
|
||||
.enter()
|
||||
.append("circle")
|
||||
.attr("cx", d => x(d.Country))
|
||||
.attr("cy", d => y(d.Value))
|
||||
.attr("cx", d => x(d.x))
|
||||
.attr("cy", d => y(d.y))
|
||||
.attr("r", "4")
|
||||
.style("fill", "yellow")
|
||||
.attr("stroke", "green");
|
||||
|
|
Loading…
Reference in New Issue
Block a user