diff --git a/nezha-fronted/src/components/chart/chart-list-grid.vue b/nezha-fronted/src/components/chart/chart-list-grid.vue index 0cf3cb698..b75cd7633 100644 --- a/nezha-fronted/src/components/chart/chart-list-grid.vue +++ b/nezha-fronted/src/components/chart/chart-list-grid.vue @@ -377,8 +377,8 @@ export default { resizeEvent: function (i, newH, newW, newHPx, newWPx) { const msg = 'RESIZE i=' + i + ', H=' + newH + ', W=' + newW + ', H(px)=' + newHPx + ', W(px)=' + newWPx this.eventLog.push(msg) - console.log(msg,this.$refs['editChart' + i]) - setTimeout(()=>{ + console.log(msg, this.$refs['editChart' + i]) + setTimeout(() => { this.$refs['editChart' + i][0].chartResize() }) }, @@ -386,9 +386,9 @@ export default { const msg = 'RESIZED i=' + i + ', X=' + newX + ', Y=' + newY + ', H(px)=' + newHPx + ', W(px)=' + newWPx this.eventLog.push(msg) console.log(msg) - setTimeout(()=>{ + setTimeout(() => { this.$refs['editChart' + i][0].chartResize() - },50) + }, 50) }, containerResizedEvent: function (i, newH, newW, newHPx, newWPx) { const msg = 'CONTAINER RESIZED i=' + i + ', H=' + newH + ', W=' + newW + ', H(px)=' + newHPx + ', W(px)=' + newWPx @@ -778,7 +778,6 @@ export default { } this.$get('visual/panel/chart?panelId=' + params.panelId + '&groupId=0' + '&pageSize=-1').then(response => { response = chartData - console.log(chartData) if (response.code === 200) { setTimeout(() => { this.finshGetData = false @@ -1802,8 +1801,8 @@ export default { this.$nextTick(() => { const chartBox = document.getElementById('chart-' + item.id) if (chartBox) { - chartBox.style.width = `100%` - chartBox.style.height = `100%` + chartBox.style.width = '100%' + chartBox.style.height = '100%' if (item.type === 'group') { chartBox.style.height = 'auto' } diff --git a/nezha-fronted/src/components/chart/chart.vue b/nezha-fronted/src/components/chart/chart.vue index 1664b821b..5f3eeac06 100644 --- a/nezha-fronted/src/components/chart/chart.vue +++ b/nezha-fronted/src/components/chart/chart.vue @@ -10,6 +10,13 @@ :chart-option="chartOption" :is-fullscreen="isFullscreen" > + { @@ -284,12 +283,10 @@ export default { this.assetData.position.mt = e.offsetY - (window.innerHeight - this.$refs.alertLabel.$el.offsetHeight) } if (boxWidth / 2 > e.offsetX) { - console.log(123) this.assetData.position.left = e.offsetX + 35 this.assetData.position.right = 0 this.LRTriangle = true } else { - console.log(456) this.assetData.position.right = boxWidth - (e.offsetX - 35) this.assetData.position.left = 0 this.LRTriangle = false diff --git a/nezha-fronted/src/components/chart/chart/chartPie.vue b/nezha-fronted/src/components/chart/chart/chartPie.vue index d57fa9761..80fd739fe 100644 --- a/nezha-fronted/src/components/chart/chart/chartPie.vue +++ b/nezha-fronted/src/components/chart/chart/chartPie.vue @@ -1,10 +1,214 @@ diff --git a/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue b/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue index f1b18b970..8b386f446 100644 --- a/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue +++ b/nezha-fronted/src/components/chart/chart/chartTimeSeries.vue @@ -102,10 +102,11 @@ export default { const valueSorted = datas.sort((a, b) => { return a[1] - b[1] }) - minTime = timeSorted[0][0] - maxTime = timeSorted[timeSorted.length - 1][0] - minValue = valueSorted[0][1] - maxValue = valueSorted[valueSorted.length - 1][1] + console.log(timeSorted, valueSorted) + minTime = timeSorted.length ? timeSorted[0][0] : '' + maxTime = timeSorted.length ? timeSorted[timeSorted.length - 1][0] : '' + minValue = valueSorted.length ? valueSorted[0][1] : '' + maxValue = valueSorted.length ? valueSorted[valueSorted.length - 1][1] : '' return { minTime, maxTime, minValue, maxValue } }, xAxisLabelFormatter (minTime, maxTime) { diff --git a/nezha-fronted/src/components/chart/chart/options/chartPie.js b/nezha-fronted/src/components/chart/chart/options/chartPie.js index 3faec2045..ce059923c 100644 --- a/nezha-fronted/src/components/chart/chart/options/chartPie.js +++ b/nezha-fronted/src/components/chart/chart/options/chartPie.js @@ -1,4 +1,29 @@ const chartPieOption = { - + tooltip: { + trigger: 'item' + }, + legend: { + show: false + }, + series: [ + { + type: 'pie', + radius: '55%', + center: ['50%', '50%'], + data: [], + label: { + show: true, + color: '#333', + position: 'inside', + rotate: true, + width: 200, + overflow: 'truncate', + ellipsis: '...' + }, + labelLine: { + show: true + } + } + ] } export default chartPieOption diff --git a/nezha-fronted/src/components/chart/chart/tools.js b/nezha-fronted/src/components/chart/chart/tools.js index 88ec2311c..2bed4c520 100644 --- a/nezha-fronted/src/components/chart/chart/tools.js +++ b/nezha-fronted/src/components/chart/chart/tools.js @@ -54,7 +54,9 @@ export function isTimeSeries (type) { export function isHexagonFigure (type) { return type === chartType.hexagonFigure } - +export function isChartPie (type) { + return type === chartType.pie +} export function isUrl (type) { return type === chartType.url } diff --git a/nezha-fronted/src/components/chart/chartList.vue b/nezha-fronted/src/components/chart/chartList.vue index 36109da01..8d48b8b78 100644 --- a/nezha-fronted/src/components/chart/chartList.vue +++ b/nezha-fronted/src/components/chart/chartList.vue @@ -141,6 +141,7 @@ export default { } catch (e) { console.info(e) } + console.log(param) param.showHeader = true return { ...item, diff --git a/nezha-fronted/src/components/chart/chartMixin.js b/nezha-fronted/src/components/chart/chartMixin.js index 8edf9bb4b..dad79e32b 100644 --- a/nezha-fronted/src/components/chart/chartMixin.js +++ b/nezha-fronted/src/components/chart/chartMixin.js @@ -1,6 +1,6 @@ import lodash from 'lodash' import { getMetricTypeValue } from '@/components/common/js/tools' -import {getChart, setChart} from '@/components/common/js/common' +import { getChart, setChart } from '@/components/common/js/common' export default { data () { return { @@ -23,34 +23,38 @@ export default { }, methods: { handleTimeSeries (chartInfo, seriesTemplate, originalDatas) { + console.log(chartInfo, seriesTemplate, originalDatas) const series = [] let colorIndex = 0 originalDatas.forEach((originalData, expressionIndex) => { originalData.forEach((data, dataIndex) => { const s = lodash.cloneDeep(seriesTemplate) - s.data = data.values - s.name = this.handleLegend(chartInfo, data, expressionIndex, dataIndex, colorIndex) - if (chartInfo.param.stack) { // 堆叠 - s.stack = 'Total' - } - if (!lodash.isEmpty(chartInfo.param.thresholds)) { // 阈值 - s.markLine = { - symbol: 'circle', - symbolSize: 5 + console.log(seriesTemplate) + if (s) { + s.data = data.values + s.name = this.handleLegend(chartInfo, data, expressionIndex, dataIndex, colorIndex) + if (chartInfo.param.stack) { // 堆叠 + s.stack = 'Total' } - s.markLine.data = chartInfo.param.thresholds.map(threshold => { - return { - yAxis: threshold.val, - lineStyle: { - color: threshold.color, - width: 2, - type: 'dotted' - } + if (!lodash.isEmpty(chartInfo.param.thresholds)) { // 阈值 + s.markLine = { + symbol: 'circle', + symbolSize: 5 } - }) + s.markLine.data = chartInfo.param.thresholds.map(threshold => { + return { + yAxis: threshold.val, + lineStyle: { + color: threshold.color, + width: 2, + type: 'dotted' + } + } + }) + } + series.push(s) + colorIndex++ } - series.push(s) - colorIndex++ }) }) return series @@ -78,13 +82,14 @@ export default { } // 处理legend别名 let alias = this.handleLegendAlias(legend, chartInfo.elements[expressionIndex].legend) + console.log(alias) if (!alias) { alias = legend } - const name = legend + '-' + chartInfo.elements[expressionIndex].id + '-' + dataIndex + const name = alias + '-' + dataIndex // 若需要统计,处理统计数据 - const statisticsTypes = chartInfo.param.legend.values + const statisticsTypes = chartInfo.param.legend ? chartInfo.param.legend.values : '' let statistics = [] if (!lodash.isEmpty(statisticsTypes)) { statistics = statisticsTypes.map(type => { @@ -111,6 +116,30 @@ export default { return aliasExpression } }, + selectMapping (value, valueMapping) { + let mapping = '' + if (valueMapping.show) { + valueMapping.mapping.forEach(item => { + if (item.type === 'value') { + if (value == item.value) { + mapping = item + } + } + if (item.type === 'range') { + if (value > item.from && value < item.to) { + mapping = item + } + } + if (item.type === 'regx') { + const reg = new RegExp(item.regx) + if (reg.test(value)) { + mapping = item + } + } + }) + } + return mapping + }, mouseEnterChart () { const myChart = getChart(this.chartId) if (myChart) { diff --git a/nezha-fronted/src/components/chart/panelChart.vue b/nezha-fronted/src/components/chart/panelChart.vue index 1a7851517..c5e9dbfb8 100644 --- a/nezha-fronted/src/components/chart/panelChart.vue +++ b/nezha-fronted/src/components/chart/panelChart.vue @@ -24,7 +24,7 @@