djoshi
Posts: 61
Joined: Fri Mar 26, 2021 5:16 pm

solidgauge segment issues on different screen sizes

I have created a "solidgauge" using 'solidgauge'.

The purpose of the gauge is to show sensor levels, and it has been segmented into three parts to represent the three different overall levels of a sensor. When the gauge is viewed on a small screen like a phone, it looks good. However, when it is viewed on a browser or tablet, the segment marks do not get larger and the gauge appears slightly distorted. Please see the images and my code below.

How can I correct this?

Looks good
b.png
b.png (7.93 KiB) Viewed 498 times
The segment due no reflect the increase size of the gauge.
a.png
a.png (27.31 KiB) Viewed 498 times

Code: Select all

  air_main_gauge() {

    const getData = () => {
      //var x=Math.floor(Math.random() * 100) + 1;
      var x = this.gauge1_value1;
      return x;
    }
    let data = getData();
    let height = document.body.offsetHeight - 600;
    this.chart = this.maingauge_chart.stockChart('MainGuageA', {
      chart: {
        type: 'solidgauge',
        backgroundColor: 'transparent',
        height: height < 160 ? 160 : height,
        events: {
          load: function () {
            const chart = this;
            setInterval(function () {
              chart.series[0].points[0].update(getData());
            }, 2000);
          }
        }
      },
      credits: {
        enabled: false
      },

      pane: {
        center: ['50%', '50%'],
        size: '100%',
        innerSize: '10%',
        startAngle: -150,
        endAngle: 150,
        background: {
          backgroundColor: HighCharts.defaultOptions.legend.backgroundColor || '#EEE',
          innerRadius: '90%',
          outerRadius: '100%',
          shape: 'arc',
          borderWidth: 0
        }
      },

      lineWidth: 1,
      tooltip: {
        enabled: false,


      },
      navigator: {
        enabled: false
      },
      rangeSelector: {
        selected: 1,
        inputEnabled: false,
        enabled: false
      },
      scrollbar: { enabled: false },
      yAxis: {
        labels: {
          enabled: false,
        },
        stops: [
          // [0.0, '#0c8eca'], // blue
          // [0.33, '#0c8eca'], // blue
          // [0.34, '#eeb333'], // yellow
          // [0.66, '#eeb333'], // yellow
          // [0.67, '#f0250a'] // red

          [0.0, '#0c8eca'], // blue
          [0.20, '#0c8eca'], // blue
          [0.21, '#eeb333'], // yellow
          [0.40, '#eeb333'], // yellow
          [0.41, '#f0250a'] // red
        ],
        min: 0,
        max: 100,
        lineWidth: 0,
        tickPositions: [100 / 3, 2 / 3 * 100],
        minorTickWidth: 0,
        zIndex: 10,
        tickColor: '#deeeee',
        tickWidth: 10,
        tickLength: 30,
        offset: 20,
      },
      plotOptions: {
        solidgauge: {
          innerRadius: '90%',
          dataLabels: {
            enabled: false
          },
          rounded: true
        },
      },
      series: [{
        //data: [this.gauge1_value1],
        data: [data],
        tooltip: {
          enabled: false
        },
      },
      ],
    });
  }
jakub.s
Posts: 1233
Joined: Fri Dec 16, 2022 11:45 am

Re: solidgauge segment issues on different screen sizes

Hi,

Thanks for the question!

You're right, it definitely shouldn't work this way.

I tried to use your config to reproduce this problem, but some things in there are missing. Could you please reproduce this issue in an online code editor like JSFiddle?

Then I'll gladly take a look & try to propose a solution.

Best regards!
Jakub
Highcharts Developer
djoshi
Posts: 61
Joined: Fri Mar 26, 2021 5:16 pm

Re: solidgauge segment issues on different screen sizes

jakub.s wrote: Mon May 22, 2023 6:36 am Hi,

Thanks for the question!

You're right, it definitely shouldn't work this way.

I tried to use your config to reproduce this problem, but some things in there are missing. Could you please reproduce this issue in an online code editor like JSFiddle?

Then I'll gladly take a look & try to propose a solution.

Best regards!
I can try to recreate it, but is there an example you can send so I base the online project on that so that i am not spending time setting up the HTML etc?
jakub.s
Posts: 1233
Joined: Fri Dec 16, 2022 11:45 am

Re: solidgauge segment issues on different screen sizes

Sure, here you go: https://jsfiddle.net/BlackLabel/tuLc1yj3/

Most of the config is from what you pasted, but some things need to be added for it to look like in the image you've attached.
Jakub
Highcharts Developer
djoshi
Posts: 61
Joined: Fri Mar 26, 2021 5:16 pm

Re: solidgauge segment issues on different screen sizes

Ok, I think found the cause of the problem. I was not able to replicate it on your fiddle code but I would like to know of any suggestions.

My code uses:

Code: Select all

let height = document.body.offsetHeight - 545;
....
....
height: height < 160 ? 160 : height,
This code was used to adjust the size of the plots, to maximise any available space. When this code is commented out, the plot segments looks fine, But when this code is applied then

Code: Select all

 tickLength: 30,
Seems like it does not make any difference to the value set.

I think tickLength Needs to be dynamic with the height.
djoshi
Posts: 61
Joined: Fri Mar 26, 2021 5:16 pm

Re: solidgauge segment issues on different screen sizes

So how can we adjust tickLength with dynamic chart sizes?
djoshi
Posts: 61
Joined: Fri Mar 26, 2021 5:16 pm

Re: solidgauge segment issues on different screen sizes

Sorry for the message.

I increase the offset from 20 to 70, and the length to 100. I changed the colour so I could see what happening. Is there a better way to set this to make it more dyanmic

This seems to have solved the issue so far but will need to perform some tests.
jakub.s
Posts: 1233
Joined: Fri Dec 16, 2022 11:45 am

Re: solidgauge segment issues on different screen sizes

Hi,

It should be quite easy to adjust the tickLength to different screen sizes.

On each chart resize the method specified in chart.events.redraw fires. In there you can check the height of the chart & update the tickLength depending on your calculations based on height.

Here's an example: https://jsfiddle.net/BlackLabel/vb8kpght/

Let me know if you have any problems.

Best regards!
Jakub
Highcharts Developer

Return to “Highcharts Stock”