Data from Excel does not show up in Bar Chart

I am trying to create a bar chart using data imported from Excel. This is how my excel file looks like.

I created the following function:

    compareDIF[a_, b_] := (
BarChart[
{
lateCondCC, lateCondEN, lateCondER,
lateExtCC, lateExtEN, lateExtER,
testEN, testER,
},
ChartStyle->{{Black, White, Gray}},
BarSpacing->{0.4, 1.0},
ChartLegends->{{"Group 1", "Group 2", "Group 3"}},
PlotRange->{{0.3,9},{-0.3, 0.5}},
Frame->{False, True, False, False},
FrameLabel->{{"Time 1", "Time 2", "Time 3"}, "label"},
Ticks->{False, False},
GridLines->{{2.8, 4.8}, {0.0}},
GridLinesStyle-> Dashed,
ImageSize->550
]
);compareDIF[a_, b_] := (
BarChart[
{
lateCondCC, lateCondEN, lateCondER,
lateExtCC, lateExtEN, lateExtER,
testEN, testER,
},
ChartStyle->{{Black, White, Gray}},
BarSpacing->{0.4, 1.0},
PlotRange->{{0.3,9},{-0.3, 0.5}},
Frame->{False, True, False, False},
Ticks->{False, False},
GridLines->{{2.8, 4.8}, {0.0}},
GridLinesStyle-> Dashed,
ImageSize->550
]
);


However, when I try running this function, Mathematica returns a bar chart with no data, such as this:

I would like to know why my code is not showing the data. I know this must be a very basic question, but I cannot find what I did wrong.

Thank you

• What about debugging it step by step? Have you tried to see what exactly does {lateCondCC, lateCondEN, lateCondER... contain?
– Kuba
Apr 24, 2018 at 20:29
• show how you use it. is b=1 ? Apr 24, 2018 at 20:46
• I use b = 4 because the data is on the fourth sheet of my excel file. I use it like this: data = compareDif['file path', 4] Apr 24, 2018 at 23:22

Assuming it is actually the case that the file you are trying to Import is laid out exactly as shown in the attached screenshot then evaluating something like Import[<path to file>] should return the following:

{
{
{"", "", "", ""},
{"", "", "", ""},
{"", "Time 1", "Time 2", "Time 3"},
{"Group 1", 1., 2., 3.},
{"Group 2", 3., 2., 1.},
{"Group 3", 1., 2., 3.}
}
}


Notice how Dimensions[%] evaluates to {1, 6, 4}; this means that in function compareDIF[a_, b_]-assuming a stands for the path to the file, which it should, since it is the only argument in Import[a]-b is in all probability redundant or defaults-manually-to 1 .

Given the Dimensions of the imported expression, it seems that the third index in the Part expressions must reference its rows while the second index is used to represent the columns; provided all this is correct, the variables ...Cond... correspond to the first column of data, the variables ...Ext... correspond to the second column of data and lastly the test... variables correspond to the last column of data.

If my guess is correct, then I think that the following template should help you obtain the result you're opting for-with appropriate adjustments:

BarChart[
Transpose[Drop[Drop[impt[[1]], 3], None, 1]],
ChartLabels -> {{"Time 1", "Time 2", "Time 3"}, None},
ChartLegends -> SwatchLegend[Automatic, {"Group 1", "Group 2", "Group 3"}],
ChartStyle -> {Automatic}
]


(in the place of Automatic you can put eg Black, White, Gray and use the rest of the Options you prefer-impt above stands for Import[a])

ps. in the initial code, the lists containing the variables in BarChart had a trailing ,` which probably didn't help.

• Ok, now I understand what the problem is. When asking Mathematica to import data from Excel, I was indexing the wrong way. In my Excel file, the variable Time 1 in Group 1 is in cell B4. If the second index in Part expressions must reference its rows and the third must reference its columns, then the indexing should be [[1, 4, 2]] in order to retrieve data from cell B4. I was doing the opposite of that - lateCondCC =dados[[b, 2, 4]], which retrieves data from cell D2. Since this is an empty cell, no data appears on my bar chart. Thanks for the help! Apr 25, 2018 at 18:26