Skip to content

How to add last stock price increase to the final label? #1686

Closed Answered by Fil
winner106 asked this question in Q&A
Discussion options

You must be logged in to vote

Here is one possibility

Plot.plot({
  style: "overflow: visible;",
  y: {
    type: "log",
    grid: true,
    label: "↑ Change in price (%)",
    tickFormat: (
      (f) => (x) =>
        f((x - 1) * 100)
    )(d3.format("+d"))
  },
  marks: [
    Plot.ruleY([1]),
    Plot.lineY(
      stocks,
      Plot.normalizeY({
        x: "Date",
        y: "Close",
        stroke: "Symbol"
      })
    ),
    Plot.text(
      stocks,
      Plot.selectLast(
        Plot.map(
          {
            text: (data) =>
              Plot.valueof(
                data,
                (d) => `${d.Symbol}\n${format( (d["Close"] / data[0].Open - 1))}`
              )
          },
          Plot.normalizeY(…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@winner106
Comment options

Answer selected by winner106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants