farmo
Posts: 6
Joined: Fri Feb 03, 2023 7:59 am

Is it possible to change windbarb marker when wind speed is 0?

I want to change windbarb marker when wind speed is 0.
Is it possible?
If so, how to do it?

My current chart looks like the capture below.
capture1.png
capture1.png (38.34 KiB) Viewed 232 times
Also you can check the link below. When the wind speed is 0, the wind direction is represented by a circle (〇).
I want to change it to custom marker, because user get confused.
So my goal is to change the marker to a horizontal line or blank (looks like the capture below).
capture2.png
capture2.png (37.58 KiB) Viewed 232 times
capture3.png
capture3.png (36.99 KiB) Viewed 232 times
---

I found some samples that change marker. In the sample, the load event is set and the marker is dynamically changed when loading is finished.
I tried the same, but could not get the data I want to use for windbarb.
User avatar
dawid.d
Posts: 835
Joined: Thu Oct 06, 2022 11:31 am

Re: Is it possible to change windbarb marker when wind speed is 0?

Hi,

Thanks for contacting us with your question!

You can do this by overriding the symbol renderer function as in the demos below:
Empty: https://jsfiddle.net/BlackLabel/v5u6Lrx3/
Line: https://jsfiddle.net/BlackLabel/b5a2wu6L/

I hope you will find it useful
Best regards!
Dawid Draguła
Highcharts Developer
farmo
Posts: 6
Joined: Fri Feb 03, 2023 7:59 am

Re: Is it possible to change windbarb marker when wind speed is 0?

Thank you for your response.
Your answer is exactly what I wanted to know and your demos really help me to understand.
However, I am struggling with implementing it in my app, because I use Highcharts in React (with Next.js).
So, it would be really helpful to get more information about changing windbarb marker in React.

---

My code looks like below.

Code: Select all

import * as H from 'highcharts';
import highchartsWindbarb from 'highcharts/modules/windbarb';
import highchartsDatagrouping from 'highcharts/modules/datagrouping';
import { setOptions } from 'highcharts';
import { useEffect, useState } from 'react';
import { Error, LineChart, Load } from '@/components';

export default function ChartPage() {
  const [opt, setOpt] = useState<Highcharts.Options>();
  const [isError, setIsError] = useState(false);
  const [isLoading, setIsLoading] = useState(false);

  // hook to setup Highcharts
  useEffect(() => {
    highchartsWindbarb(H);
    highchartsDatagrouping(H);

    setOptions({
      time: {
        useUTC: false
      }
    });
  }, []); // eslint-disable-line react-hooks/exhaustive-deps

  // hook to fetch data
  useEffect(() => {
    (async () => {
      try {
        setIsLoading(true);

        const res = await fetch(url);
        const data = await res.json();

        // ...

        setOpt(options);
        setIsLoading(false);
      } catch (error) {
        console.error(error);
        setIsError(true);
      }
    })();
  }, []); // eslint-disable-line react-hooks/exhaustive-deps

  if (isError) {
    return <Error />;
  }

  if (isLoading) {
    return <Load />;
  }

  return <LineChart options={opt} />;
}
pages/ChartPage.tsx

Code: Select all

import { Chart } from 'highcharts';
import { useEffect, useRef } from 'react';

export default function LineChart({ options }: { options: Highcharts.Options }) {
  const container = useRef<HTMLDivElement>(null);
  const myChart = useRef<Highcharts.Chart>();

  // hook to create chart
  useEffect(() => {
    if (!container.current) {
      return;
    }

    myChart.current = new Chart(container.current, options);
  }, []); // eslint-disable-line react-hooks/exhaustive-deps

  // hook to update chart
  useEffect(() => {
    if (!myChart.current) {
      return;
    }

    myChart.current.update(options);
  }, [options]);

  return <div className="w-100 h-100" ref={container}></div>;
}
components/LineChart.tsx

---

I read the document about extending Highcharts. Also, in stackoverflow, there is a thread discussing customization in Angular. So, I think my code could be something like the following.

Code: Select all

export default function customWrap(H: typeof Highcharts) {
  H.wrap(H.Series.prototype, 'windArrow', function(point: WindbarbPoint): (SVGElement|SVGPath) {
    let knots = point.value * 1.943844,
      // ...
  });
}

But how do I access to 'Series/Windbarb/WindbarbSeries.js' ?

Is this the right direction to begin with?
User avatar
dawid.d
Posts: 835
Joined: Thu Oct 06, 2022 11:31 am

Re: Is it possible to change windbarb marker when wind speed is 0?

Hi,

I'm glad it works as expected!

To apply this in react, you can use a wrap, or simply replace the function, e.g. in a defined custom module, like in the demo below.

Demo: https://codesandbox.io/s/highcharts-rea ... mModule.js

​If you have further inquiries, you may reach out to me at any time.
Regards!
Dawid Draguła
Highcharts Developer
farmo
Posts: 6
Joined: Fri Feb 03, 2023 7:59 am

Re: Is it possible to change windbarb marker when wind speed is 0?

I can change windbarb marker in my React app.
Thank you so much!!
User avatar
dawid.d
Posts: 835
Joined: Thu Oct 06, 2022 11:31 am

Re: Is it possible to change windbarb marker when wind speed is 0?

You're welcome! In case of any further questions, feel free to contact us again.
Best regards!
Dawid Draguła
Highcharts Developer

Return to “Highcharts Usage”