Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom chart values not responding #1599

Open
EMChloe opened this issue May 18, 2024 · 0 comments
Open

custom chart values not responding #1599

EMChloe opened this issue May 18, 2024 · 0 comments

Comments

@EMChloe
Copy link

EMChloe commented May 18, 2024

hi, no matter what values I change "maxValue", "minValue", "tickSize" or "minMove" to, my graph still looks completely the same. Thoughts? I am trying to change these variables to change the range of values on the y-axis, the resolution of y-axis values, as well as the increment size of the y-axis values.

Here is the code in javascript:

"const getData = async () => {
const res = await fetch('ohlcv_new.csv');
const resp = await res.text();
const cdata = resp.split('\n').map((row) => {
const [time1, open, high, low, close] = row.split(',');
return {
time: new Date(${time1}).getTime() / 1000,
open: open * 1,
high: high * 1,
low: low * 1,
close: close * 1,
};
});
return cdata;
};

const displayChart = async () => {
const chartProperties = {
width: 1500,
height: 600,
timeScale: {
timeVisible: true,
secondsVisible: false,
rightOffset: 12, // Add a right offset to make room for the y-axis
},
priceScale: {
position: 'right', // Position of the price scale
mode: 0, // Normal mode
autoScale: false,
minValue: 0,
maxValue: 30.0000,
scaleMargins: {
top: 25,
bottom: 0.5,
},
minMove: 0.0001,
tickSize: 3.0000,
tickMarkFormatter: (tickValue, index, formatter) => {
return tickValue.toFixed(4);
},
},
};

const domElement = document.getElementById('tvchart');
const chart = LightweightCharts.createChart(domElement, chartProperties);
const candleseries = chart.addCandlestickSeries();
const klinedata = await getData();
candleseries.setData(klinedata);

// Apply price format options to the candlestick series
candleseries.applyOptions({
priceFormat: {
type: 'price',
precision: 4,
minMove: 0.0001,
},
});

// Calculate the time range of the data
const firstDataPoint = klinedata[0].time;
const lastDataPoint = klinedata[klinedata.length - 1].time;
const dataRange = lastDataPoint - firstDataPoint;

// Set the visible time range to include a buffer on both ends of the data range
const buffer = 0.1; // Adjust the buffer as needed
const visibleRange = dataRange * (1 + buffer);
chart.timeScale().setVisibleRange({
from: firstDataPoint - visibleRange,
to: lastDataPoint + visibleRange,
});
};

displayChart();
"

And the associated HTML file:
"

<title>Document</title>
<script src="https://unpkg.com/lightweight-charts/dist/lightweight-charts.standalone.production.js"></script> <script src="OHLCV_CSV_STATIC.js"></script> "

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant