I see you linked a stackoverflow question where they use javascript to create a chart with google charts. I think this language is the best way to create complex charts like yours.
You mentionned that your coding skills weren't good in vba, I don't know if it is the same with javascript but I'll try to describe my code the best I can.
Here is a working code I have written for you:
https://www.funfun.io/1/#/edit/5a73067991f44418b7b84218
So as you may see, to make this example I used an online editor with an embedded spreadsheet. I enter my data in it and I access it with my code by using a JSON file, it is the short
file underneath the Settings:
{
"data": "=A1:D27"
}
After I gain access to my data, I store it in local variables, you can see that in the script.js
file. I wrote some comments so you know which variable is what. I go throw my data with $internal.data
, it's where the data from the spreadsheet is stored from column A to D, line 1 to 27:
for (var i = 0; i < $internal.data.length; i++) // $internal.data.length = 27 in this example
{
if (i == 0 || i == 14) {
country.push($internal.data[i][0]);
continue;
}
if (i > 0 && i < 13) {
months.push($internal.data[i][0]); // months
dataA.push(
[
parseInt($internal.data[i][1]), // value 2015 countryA
parseInt($internal.data[i][2]), // value 2016 countryA
parseInt($internal.data[i][3]) // value 2017 countryA
]);
}
if (i > 13 && i < 27) {
dataB.push(
[
parseInt($internal.data[i][1]), // value 2015 countryB
parseInt($internal.data[i][2]), // value 2016 countryB
parseInt($internal.data[i][3]) // value 2017 countryB
]);
}
}
After I stored my data correctly I can make my chart with a javascript library, I used Highcharts (pretty similar to google charts), it has a good documentation with lots of examples.
I put all the data and some few options in a series variable which uses the format of highcharts, like so:
var series = [];
// We enter the data we need in series
for(var i = 0; i < months.length; i++) {
series.push({
name: months[i] + " " + country[0],
type: 'column',
color: Highcharts.getOptions().colors[i+7],
data: dataA[i],
stack: country[0] // country A
});
series.push({
name: months[i] + " " + country[1],
type: 'column',
color: Highcharts.getOptions().colors[i+7],
data: dataB[i],
stack: country[1] //country B
});
}
...
// we enter series in the highchart chart
series: series
I differenciate the two countries by putting a different value in the stack
. This variable allows me to create a stacked bar chart with multiple bars with the same axis label.
Once this is done You get a chart like this:
If you don't want to display all the months you can click on the labels of the months you don't want and it will disapear, like so:
Once you have build your chart you can load it in Excel by using an excel add-in called Funfun.You just have to paste the URL of the online editor in the add-in. Here is how it looks like with my example:
You can then save the chart in different format by clicking on the top right of the chart:
I hope this helps, if I wasn't clear in my explanation don't hesitate to comment :)
Disclosure : I’m a developer of Funfun.