Time and date format not supporting at x-axis
SViswanadhaReddy opened this issue · 1 comments
Can you please explain how the TickMarkFormatter() can convert graph data from date format to time.
Currently its supporting only date format ( yyyy-mm-dd).
And also how to set intervals like 15 mins, 1 hours and 1 day based on that graph has to adjust zoom In/out ?
Hi! TickMarkFormatter is a js function in the backend library (docs are here https://tradingview.github.io/lightweight-charts/docs/api#tickmarkformatter).
We didn't find any possible ways to port that feature natively with acceptable performance. So we have implemented a feature named Plugin
.
Source code of Plugin
open class Plugin(
val uuid: String = UUID.randomUUID().toString(), //This is an id. No need to create the id by yourself
val name: String, //Unique name for plugin
val file: String, //Link to js file with proper function
val configurationParams: Any? = null //Input params for function in that file
)
Lets look in the example
class TickMarkFormatter : Plugin(
name = "tickMarkFormatter",
file = "/android_asset/plugins/tick_mark_formatter.js"
)
We've made a class implementing Plugin. The field file
is pointing somewhere in assets.
/android_asset/plugins/tick_mark_formatter.js
window.tickMarkFormatter = (pluginParams) => {
return (time, tickMarkType, locale) => {
const year = LightweightCharts.isBusinessDay(time) ? time.year : new Date(time * 1000).getUTCFullYear()
return String(year)
}
}
window.tickMarkFormatter
- this is a field for identification of the plugin (by Plugin.name). The field should be function with one input param.
pluginParams
- this is an input parameter.
Inside that function we need to return the custom formatter as describing here