Skip to content

Instantly share code, notes, and snippets.

@tkurki
Last active May 14, 2024 08:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkurki/0bb07f29987cc2af471b5e44706b00b4 to your computer and use it in GitHub Desktop.
Save tkurki/0bb07f29987cc2af471b5e44706b00b4 to your computer and use it in GitHub Desktop.
Wind Speed and Direction with Grafana ECCharts plugin
const ecData = []
if (data.series.length === 0) {
return {}
}
const time = data.series[0].fields[0].values
const direction = data.series[0].fields[1].values
const speed = data.series[1].fields[1].values
for (let i = 0; i < data.series[0].length; i++) {
ecData.push({ value: [time.get(i), Number(speed.get(i)).toFixed(2)], symbolRotate: (direction.get(i) / Math.PI * 180) - 90 })
}
const series = {
name: data.series[0].refId,
type: 'line',
showSymbol: true,
symbol: "path://m13.022 14.999v3.251c0 .412.335.75.752.75.188 0 .375-.071.518-.206 1.775-1.685 4.945-4.692 6.396-6.069.2-.189.312-.452.312-.725 0-.274-.112-.536-.312-.725-1.451-1.377-4.621-4.385-6.396-6.068-.143-.136-.33-.207-.518-.207-.417 0-.752.337-.752.75v3.251h-9.02c-.531 0-1.002.47-1.002 1v3.998c0 .53.471 1 1.002 1z",
symbolSize: 15,
areaStyle: {
opacity: 0.1,
},
lineStyle: {
width: 1,
},
data: ecData
};
/**
* Enable Data Zoom by default
*/
setTimeout(() => echartsInstance.dispatchAction({
type: 'takeGlobalCursor',
key: 'dataZoomSelect',
dataZoomSelectActive: true,
}), 500);
/**
* Update Time Range on Zoom
*/
echartsInstance.on('datazoom', function (params) {
const startValue = params.batch[0]?.startValue;
const endValue = params.batch[0]?.endValue;
locationService.partial({ from: startValue, to: endValue });
});
return {
backgroundColor: 'transparent',
tooltip: {
trigger: 'axis',
},
legend: {
left: '0',
bottom: '0',
data: ['Wind Speed & Angle'],
textStyle: {
color: 'rgba(128, 128, 128, .9)',
},
},
toolbox: {
feature: {
dataZoom: {
yAxisIndex: 'none',
icon: {
zoom: 'path://',
back: 'path://',
},
},
saveAsImage: {},
}
},
xAxis: {
type: 'time',
},
yAxis: {
type: 'value',
min: 'dataMin',
},
grid: {
left: '2%',
right: '2%',
top: '2%',
bottom: 24,
containLabel: true,
},
series,
};
@sm4l
Copy link

sm4l commented Apr 8, 2024

@fenugeek
Copy link

Use context.panel.data.series.... rather than just data.series
Make sure you use the Editor in "Code" mode, not "Visual" mode...

@Caleb79
Copy link

Caleb79 commented Apr 17, 2024

context.panel.data.series

Does this needs to be changed in the whole code (meaning everywhere)?

@garry0garry
Copy link

Is it possible to write the wind direction in letters on the graph, synchronously with the interval indicated on the time scale?

Now it's like this:
изображение
Is it possible to write the wind direction in letters on the graph, synchronously with the interval indicated on the time scale?

Now it's like this:
I want something like this (Photoshop):
изображение

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment