Skip to content

Commit

Permalink
feat: Remove double bar chart
Browse files Browse the repository at this point in the history
Signed-off-by: 1998-felix <[email protected]>
  • Loading branch information
felixgateru committed Mar 20, 2024
1 parent d38fa04 commit 1dd00f8
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 469 deletions.
5 changes: 0 additions & 5 deletions ui/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ func CreateItem() []Item {
Content: "This is a horizontal bar chart",
Widget: "horizontalBarChart",
},
{
Title: "Double Bar Chart",
Content: "This is a double bar chart",
Widget: "doubleBarChart",
},
{
Title: "Multiple Line Chart",
Content: "This is a multiple line chart",
Expand Down
145 changes: 0 additions & 145 deletions ui/web/static/js/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,150 +300,6 @@ class DonutChart extends Echart {
}
}

class DoubleBarChart extends Echart {
constructor(chartData, widgetID) {
super(widgetID, chartData);
this.Script = this.#generateScript();
}

#generateScript() {
let seriesName = this.chartData.seriesName.split(",");
return `
var doubleBarChart = echarts.init(document.getElementById("${this.ID}"));
var option = {
title: {
text: '${this.chartData.title}',
left: 'left'
},
tooltip: {
trigger: 'axis'
},
legend: {
show: true,
},
toolbox: {
show: true,
feature: {
dataView: { show: true, readOnly: false },
magicType: { show: true, type: ['line', 'bar'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
calculable: true,
xAxis: [
{
type: 'category',
// prettier-ignore
data: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
name: '${this.chartData.xAxisLabel}',
nameLocation: 'middle',
nameGap: 30
}
],
yAxis: [
{
type: 'value',
name: '${this.chartData.yAxisLabel}',
nameLocation: 'middle',
nameGap: 40
}
],
series: [
{
name: '${seriesName[0]}',
type: 'bar',
data: [
2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3
],
markPoint: {
data: [
{ type: 'max', name: 'Max' },
{ type: 'min', name: 'Min' }
]
},
markLine: {
data: [{ type: 'average', name: 'Avg' }]
}
},
{
name: '${seriesName[1]}',
type: 'bar',
data: [
2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3
],
markPoint: {
data: [
{ name: 'Max', value: 182.2, xAxis: 7, yAxis: 183 },
{ name: 'Min', value: 2.3, xAxis: 11, yAxis: 3 }
]
},
markLine: {
data: [{ type: 'average', name: 'Avg' }]
}
}
]
};
doubleBarChart.setOption(option);
var chartData = {
channels: '${this.chartData.channels}'.split(','),
things: '${this.chartData.things}'.split(','),
name: '${this.chartData.valueName}',
from: ${this.chartData.startTime},
to: ${this.chartData.stopTime},
aggregation: '${this.chartData.aggregationType}',
limit: 100,
interval:'${this.chartData.updateInterval}'
};
async function fetchData(doubleBarChart, chartData) {
try {
const dataSeries0 = [];
const dataSeries1 = [];
const xAxisArray = [];
for (let i = 0; i < chartData.channels.length; i++) {
const apiEndpoint = '${pathPrefix}/data?channel=' + chartData.channels[i] +
'&name=' + chartData.name +
'&from='+ chartData.from +
'&to=' + chartData.to +
'&aggregation=' + chartData.aggregation +
'&limit=10' +
'&interval=' + chartData.interval +
'&publisher=' + chartData.things[i];
const response = await fetch(apiEndpoint);
if (!response.ok) {
throw new Error('HTTP request failed with status:', response.status)
}
const data = await response.json();
if (data.messages != undefined && data.messages.length > 0) {
data.messages.forEach((message) => {
xAxisArray.push(new Date(message.time).toLocaleTimeString());
dataSeries0.push(message.value);
});
}
}
updateChart(horizontalBarChart, plotData);
} catch (error) {
console.error("Error fetching data:", error);
}
}
updateChart(data) {
const barChart = echarts.init(document.getElementById(this.ID));
const option = barChart.getOption();
option.series[0].data = data.seriesData;
barChart.setOption(option);
}
}
`;
}
}

class DynamicDataChart extends Echart {
constructor(chartData, widgetID) {
super(widgetID, chartData);
Expand Down Expand Up @@ -1937,7 +1793,6 @@ const chartTypes = {
areaLineChart: AreaLineChart,
timeSeriesBarChart: TimeSeriesBarChart,
donutChart: DonutChart,
doubleBarChart: DoubleBarChart,
dynamicDataChart: DynamicDataChart,
entitiesTable: EntitiesTable,
entityCount: EntityCount,
Expand Down
Loading

0 comments on commit 1dd00f8

Please sign in to comment.