nandv
Posts: 12
Joined: Sat Sep 11, 2021 5:01 am

bar count in highstock

Is it possible to annotate, or thru label, print out bar count (for OHLC bars, starting from 1st bar as 0), every say 100 bars?
and modify the tooltip (see red circle) so that not only the timestamp but also the current bar index of the select bar?

Apologize as I've tried various methods without luck. Thanks for the help!
Hj3MlsXEvq.png
Hj3MlsXEvq.png (73.36 KiB) Viewed 696 times
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: bar count in highstock

Hi,

Thanks for the question!

1. You can render custom SVG elements with Highcharts.SVGRenderer. You can render a text label/tick for each "bar interval".
API: https://api.highcharts.com/class-refere ... VGRenderer

2. You can use tooltip.headerFormat to change the content of the tooltip you marked with the red circle. You can simply add {point.index} to show the bar index.

You can read more about tooltip.headerFormat and what you can include in the API: https://api.highcharts.com/highstock/to ... aderFormat

Here's the demo: https://jsfiddle.net/BlackLabel/s074pf2c/

Let me know if that helps!

Best regards,
Jakub
Jakub
Highcharts Developer
nandv
Posts: 12
Joined: Sat Sep 11, 2021 5:01 am

Re: bar count in highstock

WoW! That was quick, and right to the point!!
I tried asking ChatGPT for 3 hrs without luck!
Thanks!
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: bar count in highstock

Haha thanks! :)

I'm glad I could help.

Do not hesitate to let me know if you have any more questions.

Jakub
Jakub
Highcharts Developer
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: bar count in highstock

I just noticed that the demo I've sent you wasn't fully responsive. Here's an updated demo: https://jsfiddle.net/BlackLabel/ox5bv1pa/
Jakub
Highcharts Developer
nandv
Posts: 12
Joined: Sat Sep 11, 2021 5:01 am

Re: bar count in highstock

Hi,
I've put into my own code and works great, except perhaps you misunderstood me,
the per 25 (or in my case 200 since it's a large dataset), should be global, instead of fixed on a selected range, so for example, 10000 bars should have labels from 200 to 9800.
Thanks
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: bar count in highstock

I'm sorry but I don't think I fully understand.

Do you want to have these "customTicks" but also use rangeSelector or navigation to scroll through the chart?

Jakub
Jakub
Highcharts Developer
nandv
Posts: 12
Joined: Sat Sep 11, 2021 5:01 am

Re: bar count in highstock

Sorry I didn't make it more clear..

The per 200 bar count display should be global, i.e., the same as the tooltip bar count, not always 200 to 1400 (in my case) for any range selected.
Jm2y0sTmOp.png
Jm2y0sTmOp.png (64.04 KiB) Viewed 684 times
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: bar count in highstock

No problem:)

How about something like this: https://jsfiddle.net/BlackLabel/7dwb8st0/

Is that what you're looking for?

Jakub
Jakub
Highcharts Developer
nandv
Posts: 12
Joined: Sat Sep 11, 2021 5:01 am

Re: bar count in highstock

thanks, the index should be global, so I've modified the code below, and it works, Thanks!

Code: Select all

		    let barInterval = 200;
		   // !! find the window's offset to the entire dataset
		    const idxoffset = series.options.data.findIndex(data => data[0] == series.points[0].category)

		    for(let i = 0; i < points.length; i += barInterval) {
			if(series.points[i].shapeArgs.x + chart.plotLeft > chart.plotLeft + chart.plotWidth - 55) continue;
			
			const customTick = chart.renderer.text(i+idxoffset, 
					series.points[i].shapeArgs.x + chart.plotLeft,
					chart.plotTop + chart.plotHeight - 20).add();
			chart.customTicks.push(customTick);
jakub.s
Posts: 1164
Joined: Fri Dec 16, 2022 11:45 am

Re: bar count in highstock

Great!

I'm glad I could help:)

Do not hesitate to let me know if you have any more questions.

Regards,
Jakub
Jakub
Highcharts Developer

Return to “Highcharts Stock”