NeBox
Posts: 44
Joined: Sun Feb 05, 2023 4:12 am

Re: Last price module does not work correctly

Thanks for the solution!

But, a couple of questions

1 - how do I now change the color of the last price label when I want red or green?

2 - how to stop updating if the chart has been moved?

Thanks.
NeBox
Posts: 44
Joined: Sun Feb 05, 2023 4:12 am

Re: Last price module does not work correctly

My Update code

Code: Select all

if (high && low)
{
	let color = 'green';

	if (open > tick.bid)
	{
		color = 'red';
	}

	let series = chart_obj.series[0];

	if (series !== undefined && series.points !== undefined)
	{
		series.points[series.points.length-1].update({
			open: open,
			high: high,
			low: low,
			close: tick.bid,
			color: color,
			lineColor: color
		});

		series.update({
			lastVisiblePrice: {
				label: {
					backgroundColor: color,
					borderColor: color,
				}
			},
			lastPrice: {
				color: color,
			}
		}, true);
	}
}
NeBox
Posts: 44
Joined: Sun Feb 05, 2023 4:12 am

Re: Last price module does not work correctly

Ok. I can change

Code: Select all

lastPrice: {
									color: color,
									label: {
										backgroundColor: color,
										borderColor: color,
									}
								}
jedrzej.r
Posts: 725
Joined: Tue Jan 24, 2023 11:21 am

Re: Last price module does not work correctly

Hi!

1. In order to change lastPrice label color, you could check last point value after update and then update series lastPrice background color based on the condition.
2. On initial load of the chart, you can set a global reference to the ID of setInterval function. Then, on afterSetExtremes event you can add a condition to check if lastPoint is inside select range, and based on the output clear or update interval of the updating point value method.

Live demo: http://jsfiddle.net/BlackLabel/q1g5u7yp/

Let me know if that was what you were looking for!
Best regards!
Jędrzej Ruta
Highcharts Developer
NeBox
Posts: 44
Joined: Sun Feb 05, 2023 4:12 am

Re: Last price module does not work correctly

Thank you for your reply.

But there is a problem. It works fine with the spline type, but it doesn't work with candlestick.

If I have candlestick type, lastPoint.isInside always returns true.
jedrzej.r
Posts: 725
Joined: Tue Jan 24, 2023 11:21 am

Re: Last price module does not work correctly

Indeed, with candlestick type, series.points is mutated on each range selecting, as well as all points have isInside flag set to true. In order to override this behaviour, you should update series.data last point. As for finding the lastPoint index, you can set a reference to last data point index on load event, and then check in afterSetExtrems if last point from series.points has the same index. Rest of the logic should be the same as in my previous example.

Live demo: https://jsfiddle.net/BlackLabel/uv7egbfo/

Let me know if you have any further questions!
Best regards!
Jędrzej Ruta
Highcharts Developer
NeBox
Posts: 44
Joined: Sun Feb 05, 2023 4:12 am

Re: Last price module does not work correctly

Thank you! Everything works perfectly.

I think these solutions should be saved somewhere in snippets or demos. This is very useful stuff.
jedrzej.r
Posts: 725
Joined: Tue Jan 24, 2023 11:21 am

Re: Last price module does not work correctly

That's great to hear!

Thanks for suggesting adding these snippets into demos, we'll keep it in memory. Luckily, Highcharts forum is effectively postioned on the internet, so if anyone looks for last price module, there is high chance they'll come across this thread.

In case of any other questions, feel free to ask anytime.
Best regards!
Jędrzej Ruta
Highcharts Developer

Return to “Highcharts Stock”