d3 axis labeling

后端 未结 6 1183
天涯浪人
天涯浪人 2020-12-12 15:55

How do I add text labels to axes in d3?

For instance, I have a simple line graph with an x and y axis.

On my x-axis, I have ticks from 1 to 10. I want the wo

6条回答
  •  囚心锁ツ
    2020-12-12 16:33

    D3 provides a pretty low-level set of components that you can use to assemble charts. You are given the building blocks, an axis component, data join, selection and SVG. It's your job to put them together to form a chart!

    If you want a conventional chart, i.e. a pair of axes, axis labels, a chart title and a plot area, why not have a look at d3fc? it is an open source set of more high-level D3 components. It includes a cartesian chart component that might be what you need:

    var chart = fc.chartSvgCartesian(
        d3.scaleLinear(),
        d3.scaleLinear()
      )
      .xLabel('Value')
      .yLabel('Sine / Cosine')
      .chartLabel('Sine and Cosine')
      .yDomain(yExtent(data))
      .xDomain(xExtent(data))
      .plotArea(multi);
    
    // render
    d3.select('#sine')
      .datum(data)
      .call(chart);
    

    You can see a more complete example here: https://d3fc.io/examples/simple/index.html

提交回复
热议问题