question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Display price scale both on left and right side

See original GitHub issue

Describe the solution you’d like

chart.applyOptions({
    priceScale: {
        position: 'both'
    }
});

Additional context Might be nice to have option for price scale on both left and right position for a big/wide chart.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SuperPenguincommented, Mar 17, 2021

Given that 3.0 now has two scales this should be a tiny addition. Right now you can only specify left or right, why not allow it on both ?

At the moment, you can use 2 series with identic properties and data, but one of them is transparent color to achieve this. Here is the example

import {
  BusinessDay,
  createChart,
  isBusinessDay,
  LineData,
  LineStyle,
  PriceLineSource,
  TickMarkType,
  UTCTimestamp
} from "lightweight-charts";

function formatTime(utcTimestamp: UTCTimestamp): string {
  const dt = new Date(utcTimestamp * 1000);
  const hour = dt.getUTCHours() < 10 ? `0${dt.getUTCHours()}` : dt.getUTCHours().toString();
  const minute = dt.getUTCMinutes() < 10 ? `0${dt.getUTCMinutes()}` : dt.getUTCMinutes().toString();

  return `${hour}:${minute}`;
}

const chartRoot = document.getElementById("main-chart") as HTMLDivElement;
const chart = createChart(chartRoot, {
  width: 400,
  height: 300,
  timeScale: {
    tickMarkFormatter: (time: UTCTimestamp | BusinessDay, tickMarkType: TickMarkType, locale: string) => {
      if (isBusinessDay(time)) {
        return "";
      } else {
        return formatTime(time);
      }
    }
  },
  localization: {
    timeFormatter: (time: BusinessDay | UTCTimestamp) => {
      if (isBusinessDay(time)) {
        return "";
      } else {
        return formatTime(time);
      }
    }
  },
  leftPriceScale: {
    visible: true
  }
});

const lineLeft = chart.addLineSeries({
  priceScaleId: "left",
  color: "#FF000000", // Red Transparent
  lineStyle: LineStyle.Solid,
  lineWidth: 1,
  priceLineSource: PriceLineSource.LastVisible
});

const lineRight = chart.addLineSeries({
  color: "#FF0000", // Red
  lineStyle: LineStyle.Solid,
  lineWidth: 1,
  priceLineSource: PriceLineSource.LastVisible
});

const data: LineData[] = [];
const now = Math.round(Date.now() / 60000) * 60000;

for (let i = 1; i < 1000; i++) {
  const value = Math.sin((i * 10 * Math.PI) / 180);

  data.push({
    time: (now + i * 60) as UTCTimestamp,
    value: value
  });
}

lineLeft.setData(data);
lineRight.setData(data);

image

0reactions
timocovcommented, Mar 22, 2021

Ah, I see, we didn’t plan to add this feature though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to place all the scales on the right or left? - TradingView
In the chart settings, you can set the right or left side of a chart to place all the price scales: Look first...
Read more >
Chart Scale and Scale Adjusting - Sierra Chart
Right-click on the Values Scale on the right side of the chart. The Scale menu will display. Select the Scale Range that you...
Read more >
Price Scale - MultiCharts
In the Settings section, check Left or/and Right check boxes to display the scale on the left or/and on the right side of...
Read more >
TradingView indicator price scale - Kodify.net
Since that makes the indicator's values not show up on the left or right price axis, the indicator displays on the full chart...
Read more >
I'd like to display the price label at the end of the right screen ...
When you select the right side of the label position, only the maximum line.get_x2(lineLast) is moved. I would appreciate it if you could...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found