I'm trying to get an example of an eCharts 5 chart as a configurable function
I want to be able to pass in data + Id's to plot in multiple containers without repeating code
(Currently transitioning from d3.js to eCharts and not the best at JS in general so apologies for my stupidity)
The example seems below seems to fail because of a 'Uncaught TypeError: Cannot read property 'getAttribute' of null'
I interpreted that as the chart attempting to be drawn before the DOM is loaded, so I added the window.onload as a shot in the dark "fix"
Currently no errors, but no plots, so my "fix" is probably way off
Thanks for your time + suggestions
https://codepen.io/kml-projects/pen/abwRwEb
UPDATE: This is a working bar chart example -- will be tinkering with this and post a solution if I find one
https://codepen.io/kml-projects/pen/OJgBaQx
function createChart(divId,data) {
var myChart = echarts.init(document.getElementById(divId));
var app = {};
var option;
option = {
title: {
text: 'Basic Radar Chart'
},
legend: {
data: ['Allocated Budget', 'Actual Spending']
},
radar: {
// shape: 'circle',
indicator: [
{ name: 'Sales', max: 6500 },
{ name: 'Administration', max: 16000 },
{ name: 'Information Technology', max: 30000 },
{ name: 'Customer Support', max: 38000 },
{ name: 'Development', max: 52000 },
{ name: 'Marketing', max: 25000 }
]
},
series: [
{
name: 'Budget vs spending',
type: 'radar',
data: [
{
value: data,
},
]
}
]
};
myChart.setOption(option);
};
var data1 = [4200, 3000, 20000, 35000, 50000, 18000];
var data2 = [5000, 14000, 28000, 26000, 42000, 21000];
window.onload = function () {
createChart('main', data1 );
createChart('main-2', data2 );
};
<!DOCTYPE html>
<html style="height: 100%">
<head>
<meta charset="utf-8">
</head>
<body style="height: 100%; margin: 0">
<div id="container" style="height: 100%"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
<div id="main" style="width: 600px;height:400px;"></div>
<div id="main-2" style="width: 600px;height:400px;"></div>
</body>
</html>
Figured it out