{"id":1532,"date":"2020-09-10T09:51:34","date_gmt":"2020-09-10T09:51:34","guid":{"rendered":"https:\/\/www.ipcpu.com\/?p=1532"},"modified":"2021-09-10T09:52:09","modified_gmt":"2021-09-10T09:52:09","slug":"grafana-echarts","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2020\/09\/grafana-echarts\/","title":{"rendered":"Grafana\u4e2decharts\u63d2\u4ef6\u4f7f\u7528"},"content":{"rendered":"

Grafana\u63d2\u4ef6\u4f7f\u7528.md<\/p>\n

\u6982\u8ff0<\/h2>\n

Grafana\u62e5\u6709\u4e30\u5bcc\u7684\u56fe\u6807\u529f\u80fd\uff0c\u80fd\u5f88\u65b9\u4fbf\u7684\u4ecePrometheus\u3001Zabbix\u3001MySQL\u4e2d\u8bfb\u53d6\u76f8\u5173\u7684\u6570\u636e\uff0c\u5bf9\u4e8e\u8fd0\u7ef4\u4eba\u5458\u6765\u8bb2\uff0c\u662f\u6bcf\u65e5\u5fc5\u770b\u7684\u7ad9\u70b9\u3002
\n\u4f46\u662f\u5bf9\u4e8e\u4e00\u4e9b\u590d\u6742\u7684\u56fe\u5f62\uff0c\u4ed6\u7684\u5904\u7406\u529f\u80fd\u5c31\u6bd4\u8f83\u5f31\u4e86\uff0c\u8fd9\u65f6\u6211\u4eec\u60f3\u5230\u4e86\u767e\u5ea6\u7684echarts\uff0c\u6709\u6ca1\u6709\u7c7b\u4f3c\u63d2\u4ef6\u5462\uff1f\u8fd8\u771f\u88ab\u6211\u4eec\u627e\u5230\u4e86\u3002
\n\u5b98\u7f51\u5730\u5740\u662f\uff1a <\/a>https:\/\/github.com\/Billiballa\/bilibala-echarts-panel<\/a><\/p>\n

echarts\u63d2\u4ef6\u7b80\u5355\u4ecb\u7ecd<\/h2>\n

\u8fd9\u4e2a\u63d2\u4ef6\u76ee\u524d\u652f\u6301echarts 4.9 \uff0c\u6839\u636eecharts\u7684\u6587\u6863\uff0c\u6211\u4eec\u53ea\u9700\u8981\u7ed9\u51faoption\uff0c \u5c31\u53ef\u4ee5\u505a\u51fa\u56fe\u5f62\uff0c\u5982\u4e0b\uff0c
\n
\n\u8fd9\u4e2a\u63d2\u4ef6\u4e5f\u5f88\u7b80\u5355\uff0c\u5c31\u63d0\u4f9b\u4e86\u4e00\u4e2aEcharts Option\uff0c\u53ef\u4ee5\u81ea\u884c\u7f16\u5199\u4e00\u4e9b\u51fd\u6570\uff0c\u6700\u7ec8return echarts\u4e2doption\u5185\u5bb9\u5c31\u53ef\u4ee5\u4e86\u3002
\n
\n\u6ce8\u610f\uff1a\u5b98\u65b9\u8fd8\u5728Echarts Option\u4e0a\u65b9\u63d0\u4f9bFollowGrafanaTheme \u5f00\u5173\uff0c\u6ca1\u4ec0\u4e48\u7528\uff0c\u5360\u9875\u9762\u5730\u76d8\uff0c\u88ab\u6211\u5220\u6389\u4e86\u3002<\/p>\n

\u4f7f\u7528echarts\u5236\u4f5c\u5927\u76d8<\/h2>\n

\u7ecf\u8fc7\u4e00\u756a\u4e86\u89e3\uff0c\u53d1\u73b0\u63d2\u4ef6\u81ea\u5e26\u7684\u7b2c\u4e00\u4e2a\u51fd\u6570\u7528\u4e8e\u4ece\u6570\u636e\u6e90\u67e5\u8be2\u51fa\u6765\u7684time\u548cvalue\u6570\u636e\u4f20\u9012\uff0c\u56e0\u4e3a\u6211\u4eec\u7684\u6570\u636e\u4e0d\u662f\u65f6\u5e8f\u578b\u6570\u636e\uff0c\u5f88\u96be\u901a\u8fc7\u8fd9\u4e2a\u65b9\u6cd5\u4f20\u9012\u3002
\n\u540e\u6765\u53c8\u53d1\u73b0\u8fd9\u4e2a\u63d2\u4ef6\u652f\u6301ajax\uff0c\u53ef\u4ee5\u53d1\u8d77ajax\u8bf7\u6c42\u83b7\u53d6\u8fdc\u7a0b\u7684\u6570\u636e\uff0c\u56e0\u6b64\u6211\u4eec\u76f4\u63a5\u8c03\u7528\u4e86\u8fdc\u7a0b\u6570\u636e\u3002
\n
\n\u6700\u7ec8\u6211\u4eec\u505a\u51fa\u7684\u5927\u76d8\u5982\u4e0a\u56fe\uff0c\u4e3b\u8981\u7528\u6765\u5206\u6790\u963f\u91cc\u4e91OSS\u5b58\u50a8\u7684\u8d26\u5355\uff0c\u90a3\u4e00\u9879\u82b1\u8d39\u6bd4\u8f83\u591a\uff0c\u54ea\u4e2abucket\u82b1\u8d39\u6bd4\u8f83\u591a\uff0c\u54ea\u4e2a\u8ba1\u8d39\u9879\u82b1\u8d39\u6bd4\u8f83\u591a\uff0c\u53ef\u4ee5\u4e00\u76ee\u4e86\u7136\u3002
\n\u6211\u4eec\u7684\u4ee3\u7801\u5982\u4e0b<\/p>\n

\n
option = {\n         title: [ \n    {text: '\u672c\u6708OSS\u603b\u8d39\u7528',x: '2%',y: '0%',\n             textStyle: {fontSize: 16, color: \"#bd9f00\"}},\n    {text: '',x: '12%',y: '0%',\n              textStyle: {fontSize: 16, color: \"#ffdd29\"}},\n     {text: '\u8ba1\u8d39\u9879\u5360\u6bd4',x: '49%',y: '47%',\n                textStyle: {fontSize: 18, color: \"#fff\"}},\n],\n    tooltip: {\n        trigger: 'item',\n        formatter: '{a} <br\/>{b}: {c} ({d}%)'\n    },\n     grid: [\n         {left: '2%', \/\/ \u7f51\u683c\u90e8\u5206\n             right: '65%',\n             top: '10%',\n             bottom: '2%',\n             containLabel: true\n         },\n         {left: '75%', \/\/ \u7f51\u683c\u90e8\u5206\n             right: '2%',\n             top: '10%',\n             bottom: '45%',\n             containLabel: true\n         },\n         {left: '75%', \/\/ \u7f51\u683c\u90e8\u5206\n             right: '2%',\n             top: '65%',\n             bottom: '0%',\n             containLabel: true\n         },\n           ],\n    xAxis: [\n        {gridIndex: 0,type: 'value',axisLabel: {\n                    textStyle: {\n                        color: '#c9c9ca'\n                    }\n                },splitLine: {\n              lineStyle: {\n                type: \"dotted\"\n              }\n            }},\n        {gridIndex: 1,type: 'value',  position: 'top', inverse:true, axisLabel: {\n                    textStyle: {\n                        color: '#c9c9ca'\n                    }\n                },splitLine: {\n              lineStyle: {\n                type: \"dotted\"\n              }\n            }},\n        {gridIndex: 2,type: 'value',  position: 'top', inverse:true, axisLabel: {\n                    textStyle: {\n                        color: '#c9c9ca'\n                    }\n                },splitLine: {\n              lineStyle: {\n                type: \"dotted\"\n              }\n            }},\n    ],\n    yAxis: [\n        {gridIndex: 0, type: 'category' ,position: 'top'},  \n        {gridIndex: 1, type: 'category' , inverse:true, }, \n        {gridIndex: 2, type: 'category' , inverse:false, },  \n    ],\n    color: [\"#87f7cf\", \"#f7f494\", \"#72ccff\", \"#f7c5a0\", \"#fc97af\", \"#d4a4eb\", \"#d2f5a6\", \"#76f2f2\"],\n    series: [\n        {\n            name: '\u8d39\u7528\u7c7b\u522b',\n            type: 'pie',\n            center: ['54%', '50%'],\n            radius: ['35%', '60%'],\n            avoidLabelOverlap: true,\n            color: [ \"#f7f494\", \"#72ccff\", \"#f7c5a0\", \"#87f7cf\",\"#fc97af\", \"#d4a4eb\", \"#d2f5a6\", \"#76f2f2\"],\n            label: {\n                show: true,\n                position: 'outside',\n                formatter: '{a|{b}\uff1a{d}%}\\n{hr|}',\n                rich: {\n                    hr: {\n                        borderRadius: 3,\n                        width: 3,\n                        height: 3,\n                        padding: [3, 3, 0, -12]\n                    },\n                    a: {\n                        padding: [-30, 15, -20, 15]\n                    }\n                 }\n            },\n            labelLine: {\n                normal: {\n                    length: 20,\n                    length2: 30,\n                    lineStyle: {\n                        width: 1,\n                        color: '#fff'\n                    }\n                }\n            },\n            emphasis: {\n                label: {\n                    show: true,\n                    fontSize: '30',\n                    fontWeight: 'bold'\n                }\n            },\n            labelLine: {\n                show: true\n            }\n        },\n        {\n            name:'\u8d39\u7528\u7c7b\u522b',\n            type: 'bar', \n            xAxisIndex: 0, \n            yAxisIndex: 0,\n            label: {\n                normal: {\n                    show: true,\n                    position: 'right',\n                    formatter: '{b} {c}'\n                }\n            }\n        },\n        {\n            name:'\u8d39\u7528\u7c7b\u522b',\n            type: 'bar', \n            color: [  \"#72ccff\", \"#f7c5a0\", \"#f7f494\",\"#87f7cf\",\"#fc97af\", \"#d4a4eb\", \"#d2f5a6\", \"#76f2f2\"],\n            xAxisIndex: 1, \n            yAxisIndex: 1,\n            label: {\n                normal: {\n                    show: true,\n                    position: 'left',\n                    formatter: '{b} {c}'\n                }\n            }\n        },\n         {\n            name:'\u8d39\u7528\u7c7b\u522b',\n            type: 'bar', \n            color: [  \"#e0cfeb\", \"#d2f5a6\", \"#76f2f2\"],\n            xAxisIndex: 2,  \n            yAxisIndex: 2,\n            label: {\n                normal: {\n                    show: true,\n                    position: 'left',\n                    formatter: '{b} {c}'\n                }\n            }\n        },\n    ]\n};\n\n$.ajax({\n    url: \"https:\/\/json.ipcpu.com\/json\/ossdata.json\",\n  type: 'GET',\n    dataType: 'json',\n    error: function (request, error) {\n        console.log(\" Can't do because: \" + error);\n  },\n  success: function (res) {\n      if (res) {\n      option.series[0].data = res.itemdata;\n      option.series[1].data = res.itemdata;\n      option.series[2].data = res.bucketdata.slice(0,5);\n      option.series[3].data = res.detaildata.slice(0,5);\n      option.title[1].text = res.totalfee;\n      echartsInstance.setOption(option)\n    }\n}\n});<\/code><\/pre>\n<\/div>\n

\u4ee3\u7801\u7b2c\u4e00\u90e8\u5206\uff0coption\u7528\u6765\u5b9a\u4e49\u4e86echarts\u56fe\u8868\u7684\u5c5e\u6027\uff1b\u7b2c\u4e8c\u90e8\u5206\u662f\u8c03\u7528\u4e86ajax\u83b7\u53d6\u8fdc\u7a0b\u7684json\u6570\u636e\u6765\u5bf9\u56fe\u8868\u8fdb\u884c\u7ed8\u5236\u3002<\/p>\n

\u603b\u7ed3<\/h2>\n

\u65f6\u5e8f\u578b\u6570\u636e(time series data) \u6709\u591a\u4e2aTime-Value\uff08\u65f6\u95f4\u6233\u548c\u503c\u7684\u7ec4\u5408\uff09\u6784\u6210\uff0cGrafana\u3001Prometheus\u5c31\u662f\u4e13\u95e8\u5904\u7406\u8fd9\u79cd\u6570\u636e\u7684\uff1b\u5728\u5904\u7406\u5176\u4ed6\u6570\u636e\u7684\u65f6\u5019\u5c31\u975e\u5e38\u4e0d\u53cb\u597d\u4e86\u3002
\n\u672c\u4f8b\u4e2d\u6211\u4eec\u901a\u8fc7ajax\u83b7\u53d6\u7684json\u6570\u636e\uff0c\u4f7f\u7528echarts\u56fe\u5f62\u7ec4\u4ef6\u8fdb\u884c\u5c55\u793a\uff0c\u4ec5\u4ec5\u662f\u5728Grafana\u4e0a\u52a0\u4e86\u4e00\u4e2a\u9875\u9762\uff0c\u4e0eGrafana\u672c\u8eab\u5173\u7cfb\u4e0d\u5927\uff0c\u6211\u4eec\u5b9e\u73b0\u7684\u529f\u80fd\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u632a\u5230\u5176\u4ed6HTML\u9875\u9762\u4e0a\u3002<\/p>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » Grafana\u4e2decharts\u63d2\u4ef6\u4f7f\u7528<\/a><\/p>","protected":false},"excerpt":{"rendered":"

Grafana\u63d2\u4ef6\u4f7f\u7528.md \u6982\u8ff0 Grafana\u62e5\u6709\u4e30\u5bcc\u7684\u56fe\u6807\u529f\u80fd\uff0c\u80fd\u5f88\u65b9\u4fbf\u7684\u4ecePrometheus\u3001Zabbix\u3001MySQL\u4e2d\u8bfb\u53d6\u76f8\u5173\u7684\u6570\u636e\uff0c\u5bf9\u4e8e\u8fd0\u7ef4\u4eba\u5458\u6765\u8bb2\uff0c\u662f\u6bcf\u65e5\u5fc5\u770b\u7684\u7ad9\u70b9\u3002 \u4f46\u662f\u5bf9\u4e8e\u4e00\u4e9b\u590d\u6742\u7684\u56fe\u5f62\uff0c\u4ed6\u7684\u5904\u7406\u529f\u80fd\u5c31\u6bd4\u8f83\u5f31\u4e86\uff0c\u8fd9\u65f6\u6211\u4eec\u60f3\u5230\u4e86\u767e\u5ea6\u7684echarts\uff0c\u6709\u6ca1\u6709\u7c7b\u4f3c\u63d2\u4ef6\u5462\uff1f\u8fd8\u771f\u88ab\u6211\u4eec\u627e\u5230\u4e86\u3002 \u5b98\u7f51\u5730\u5740\u662f\uff1a https:\/\/github.com\/Billiballa\/bilibala-echarts-panel echarts\u63d2\u4ef6\u7b80\u5355\u4ecb\u7ecd \u8fd9\u4e2a\u63d2\u4ef6\u76ee\u524d\u652f\u6301echarts 4.9 \uff0c\u6839\u636eecharts\u7684\u6587\u6863\uff0c\u6211\u4eec\u53ea\u9700\u8981\u7ed9\u51faoption\uff0c \u5c31\u53ef\u4ee5\u505a\u51fa\u56fe\u5f62\uff0c\u5982\u4e0b\uff0c \u8fd9\u4e2a\u63d2\u4ef6\u4e5f\u5f88\u7b80\u5355\uff0c\u5c31\u63d0\u4f9b\u4e86\u4e00\u4e2aEcharts Option\uff0c\u53ef\u4ee5\u81ea\u884c\u7f16\u5199\u4e00\u4e9b\u51fd\u6570\uff0c\u6700\u7ec8return echarts\u4e2doption\u5185\u5bb9\u5c31\u53ef\u4ee5\u4e86\u3002 \u6ce8\u610f\uff1a\u5b98\u65b9\u8fd8\u5728Echarts Option\u4e0a\u65b9\u63d0\u4f9bFollowGrafanaTheme \u5f00\u5173\uff0c\u6ca1\u4ec0\u4e48\u7528\uff0c\u5360\u9875\u9762\u5730\u76d8\uff0c\u88ab\u6211\u5220\u6389\u4e86\u3002 \u4f7f\u7528echarts\u5236\u4f5c\u5927\u76d8 \u7ecf\u8fc7\u4e00\u756a\u4e86\u89e3\uff0c\u53d1\u73b0\u63d2\u4ef6\u81ea\u5e26\u7684\u7b2c\u4e00\u4e2a\u51fd\u6570\u7528\u4e8e\u4ece\u6570\u636e\u6e90\u67e5\u8be2\u51fa\u6765\u7684time\u548cvalue\u6570\u636e\u4f20\u9012\uff0c\u56e0\u4e3a\u6211\u4eec\u7684\u6570\u636e\u4e0d\u662f\u65f6\u5e8f\u578b\u6570\u636e\uff0c\u5f88\u96be\u901a\u8fc7\u8fd9\u4e2a\u65b9\u6cd5\u4f20\u9012\u3002 \u540e\u6765\u53c8\u53d1\u73b0\u8fd9\u4e2a\u63d2\u4ef6\u652f\u6301ajax\uff0c\u53ef\u4ee5\u53d1\u8d77ajax\u8bf7\u6c42\u83b7\u53d6\u8fdc\u7a0b\u7684\u6570\u636e\uff0c\u56e0\u6b64\u6211\u4eec\u76f4\u63a5\u8c03\u7528\u4e86\u8fdc\u7a0b\u6570\u636e\u3002 \u6700\u7ec8\u6211\u4eec\u505a\u51fa\u7684\u5927\u76d8\u5982\u4e0a\u56fe\uff0c\u4e3b\u8981\u7528\u6765\u5206\u6790\u963f\u91cc\u4e91OSS\u5b58\u50a8\u7684\u8d26\u5355\uff0c\u90a3\u4e00\u9879\u82b1\u8d39\u6bd4\u8f83\u591a\uff0c\u54ea\u4e2abucket\u82b1\u8d39\u6bd4\u8f83\u591a\uff0c\u54ea\u4e2a\u8ba1\u8d39\u9879\u82b1\u8d39\u6bd4\u8f83\u591a\uff0c\u53ef\u4ee5\u4e00\u76ee\u4e86\u7136\u3002 \u6211\u4eec\u7684\u4ee3\u7801\u5982\u4e0b option = { title: [ {text: ‘\u672c\u6708OSS\u603b\u8d39\u7528’,x: ‘2%’,y: ‘0%’, textStyle: {fontSize: 16, color: “#bd9f00″}}, {text: ”,x: ‘12%’,y: ‘0%’, textStyle: {fontSize: 16, color: “#ffdd29”}}, {text: ‘\u8ba1\u8d39\u9879\u5360\u6bd4’,x: ‘49%’,y: ‘47%’, textStyle: {fontSize: 18, color: “#fff”}}, ], […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[180,219],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1532"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1532"}],"version-history":[{"count":1,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1532\/revisions"}],"predecessor-version":[{"id":1533,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1532\/revisions\/1533"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}