jQWidgets jqxGauge LinearGauge 指针属性

  • Post category:jquery

jQWidgets jqxGauge LinearGauge 指针属性

jQWidgets是一个基于jQuery的UI组件库,提供了丰富的UI组件和工具,包括表格、图表、日历、菜单等。jqxGaugejqxLinearGaugejQWidgets中的两个组件,用于显示仪表盘和线性仪表盘。这两个组件都提供了指针属性,用于设置指针的样式和位置。

指针属性的基本语法

指针属性用于设置指针的样式和位置。其基本语法如下:

// 设置仪表盘指针
$('#jqxGauge').jqxGauge({
  pointer: {
    length: '60%',
    width: 10,
    style: { fill: '#000000' },
    position: { x: 55, y: 200 }
  }
});

// 设置线性仪表盘指针
$('#jqxLinearGauge').jqxLinearGauge({
  pointer: {
    type: 'arrow',
    size: '5%',
    style: { fill: '#000000' },
    position: '50%'
  }
});

jqxGaugejqxLinearGauge组件中,可以使用指针属性来设置指针的样式和位置。

示例1:设置jqxGauge指针

以下是一个示例,演示如何使用指针属性设置jqxGauge的指针:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>jQWidgets Gauge Example</title>
  <link rel="stylesheet" href="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/styles/jqx.base.css">
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/jqxcore.js"></script>
  <script src="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/jqxdata.js"></script>
  <script src="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/jqxbuttons.js"></script>
  <script src="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/jqxgauge.js"></script>
</head>
<body>
  <div id="jqxGauge"></div>
  <script>
    $(document).ready(function () {
      $('#jqxGauge').jqxGauge({
        ranges: [
          { startValue: 0, endValue: 50, style: { fill: '#4cb848', stroke: '#4cb848' }, startDistance: 0, endDistance: 0 },
          { startValue: 50, endValue: 90, style: { fill: '#fad00b', stroke: '#fad00b' }, startDistance: 0, endDistance: 0 },
          { startValue: 90, endValue: 100, style: { fill: '#e00000', stroke: '#e00000' }, startDistance: 0, endDistance: 0 }
        ],
        value: 75,
        pointer: {
          length: '60%',
          width: 10,
          style: { fill: '#000000' },
          position: { x: 55, y: 200 }
        }
      });
    });
  </script>
</body>
</html>

在这个示例中,我们使用jqxGauge组件创建了一个仪表盘,并使用指针属性设置了指针的样式和位置。

示例2:设置jqxLinearGauge指针

以下是另一个示例,演示如何使用指针属性设置jqxLinearGauge的指针:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>jQWidgets LinearGauge Example</title>
  <link rel="stylesheet" href="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/styles/jqx.base.css">
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/jqxcore.js"></script>
  <script src="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/jqxdata.js"></script>
  <script src="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/jqxbuttons.js"></script>
  <script src="https://cdn.jqwidgets.com/jquery.jqwidgets/4.5.3/jqwidgets/jqxlineargauge.js"></script>
</head>
<body>
  <div id="jqxLinearGauge"></div>
  <script>
    $(document).ready(function () {
      $('#jqxLinearGauge').jqxLinearGauge({
        orientation: 'vertical',
        ticksMajor: { size: '10%', interval: 10 },
        ticksMinor: { size: '5%', interval: 2.5, style: { 'stroke-width': 1, stroke: '#aaaaaa' } },
        max: 100,
        min: 0,
        value: 75,
        pointer: {
          type: 'arrow',
          size: '5%',
          style: { fill: '#000000' },
          position: '50%'
        },
        ranges: [
          { startValue: 0, endValue: 30, style: { fill: '#4cb848', stroke: '#4cb848' }, start: '0%', endDistance: '25%' },
          { startValue: 30, endValue: 70, style: { fill: '#fad00b', stroke: '#fad00b' }, startDistance: '0%', endDistance: '25%' },
          { startValue: 70, endValue: 100, style: { fill: '#e00000', stroke: '#e00000' }, startDistance: '0%', endDistance: '25%' }
        ]
      });
    });
  </script>
</body>
</html>

在这个示例中,我们使用jqxLinearGauge组件创建了一个线性仪表盘,并使用指针属性设置了指针的样式和位置。

综上所述,jqxGaugejqxLinearGauge组件都提供了指针属性,用于设置指针的样式和位置。本文详细介绍了指针属性的使用和示例。

参考