Rumah > hujung hadapan web > tutorial js > 用js实现汽车仪表盘

用js实现汽车仪表盘

php中世界最好的语言
Lepaskan: 2018-04-17 17:10:04
asal
4459 orang telah melayarinya

这次给大家带来用js实现汽车仪表盘,用js实现汽车仪表盘的注意事项有哪些,下面就是实战案例,一起来看一下。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

<!DOCTYPE html>

<html>

<head lang="en">

    <meta charset="UTF-8">

    <title></title>

    <style>

        #test,#hehe{

            width: 100%;

            height: 500px;

        }

    </style>

</head>

<body>

<p id="test"></p>

<p id="hehe"></p>

</body>

<script src="js/jquery.min.js"></script>

<script src="js/echarts-all.js"></script>

<script>

    var myChart1;

    var option = {

        tooltip : {

            trigger: 'axis'

        },

        legend: {

            data:['最高','最低']

        },

        toolbox: {

            show : true,

            feature : {

                mark : {show: true},

                dataView : {readOnly:false},

                magicType : {show: true, type: ['line''bar''stack''tiled']},

                restore : {show: true},

                saveAsImage : {show: true}

            }

        },

        calculable : true,

        xAxis : [

            {

                type : 'category',

                boundaryGap : true,

                data : function (){

                    var list = [];

                    for (var i = 1; i <= 30; i++) {

                        list.push(&#39;2013-03-&#39; + i);

                    }

                    return list;

                }()

            }

        ],

        yAxis : [

            {

                type : &#39;value&#39;

            }

        ],

        series : [

            {

                name:&#39;最低&#39;,

                type:&#39;bar&#39;,

                data:function (){

                    var list = [];

                    for (var i = 1; i <= 5; i++) {

                        list.push(Math.round(Math.random()* 10));

                    }

                    return list;

                }()

            }

        ]

    };

    myChart=echarts.init(document.getElementById(&#39;test&#39;));

    myChart.setOption(option);

    var ecConfig = echarts.config;

    myChart1=echarts.init(document.getElementById(&#39;hehe&#39;));

    myChart.on(ecConfig.EVENT.HOVER, function(params){

        var data=params.value;

        var option1 = {

            tooltip : {

                formatter: "{a} <br/>{b} : {c}%"

            },

            toolbox: {

                show : true,

                feature : {

                    mark : {show: true},

                    restore : {show: true},

                    saveAsImage : {show: true}

                }

            },

            series : [

                {

                    name:'业务指标',

                    type:'gauge',

                    startAngle: 180,

                    endAngle: 0,

                    center : ['50%''90%'],    // 默认全局居中

                    radius : 320,

                    axisLine: {            // 坐标轴线

                        lineStyle: {       // 属性lineStyle控制线条样式

                            width: 200

                        }

                    },

                    axisTick: {            // 坐标轴小标记

                        splitNumber: 10,   // 每份split细分多少段

                        length :12,        // 属性length控制线长

                    },

                    axisLabel: {           // 坐标轴文本标签,详见axis.axisLabel

                        formatter: function(v){

                            switch (v+''){

                                case '10'return '低';

                                case '50'return '中';

                                case '90'return '高';

                                defaultreturn '';

                            }

                        },

                        textStyle: {       // 其余属性默认使用全局文本样式,详见TEXTSTYLE

                            color: '#fff',

                            fontSize: 15,

                            fontWeight: 'bolder'

                        }

                    },

                    pointer: {

                        width:50,

                        length: '90%',

                        color: 'rgba(255, 255, 255, 0.8)'

                    },

                    title : {

                        show : true,

                        offsetCenter: [0, '-60%'],       // x, y,单位px

                        textStyle: {       // 其余属性默认使用全局文本样式,详见TEXTSTYLE

                            color: '#fff',

                            fontSize: 30

                        }

                    },

                    detail : {

                        show : true,

                        backgroundColor: 'rgba(0,0,0,0)',

                        borderWidth: 0,

                        borderColor: '#ccc',

                        width: 100,

                        height: 40,

                        offsetCenter: [0, -40],       // x, y,单位px

                        formatter:'{value}%',

                        textStyle: {       // 其余属性默认使用全局文本样式,详见TEXTSTYLE

                            fontSize : 50

                        }

                    },

                    data:[{value: data*10, name: '完成率'}]

                }

            ]

        };

        option1.series[0].data[0].value = data;

        myChart1.setOption(option1,true);

    });

//    myChart.on(ecConfig.EVENT.DATA_ZOOM, eConsole);

//    myChart.on(ecConfig.EVENT.LEGEND_SELECTED, eConsole);

//    myChart.on(ecConfig.EVENT.MAGIC_TYPE_CHANGED, eConsole);

//    myChart.on(ecConfig.EVENT.DATA_VIEW_CHANGED, eConsole);

</script>

</html>

Salin selepas log masuk

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

canvas与JS实现动态时钟动画

优化页面加载速度插件InstantClick

预加载InstantClick使用详解

Atas ialah kandungan terperinci 用js实现汽车仪表盘. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan