Simple Problem with Pie Chart on Thingspeak using MATLAB Visualization

I'm trying to create a pie chart with the energy comsumption of some of my electronic devices. I made a simple code for testing:
Flow the logic:
1) Receives energy consumption of a cicle (interval) from TV (field 1) and Lights (field 2) [ESP calculates in X seconds how much energy was used and sends it]
2) In 'Field Chart' I select 'Sum' as 'Daily', so each time it receives an energy consumption this value is added to the previous one.
Now about the MATLAB Visualization code:
I got a pie chart using 'pie(X)' with X being a vector of only 2 numbers (energy from TV and energy from Lights). But the sum of the only two numbers not equals 100%. One thing that I did notice is that the proportion of the yellow and the blue slices is correct (when compared with the values that are displayed at the Field Charts), but I don't know what is the missing part of the pie. Look at the pie chart that I got:
My objective is to show how one device affects the total daily consumption in comparison with another device. So, with the last value added to the daily sum of one field I want to use it as a slice of the pie in the chart. So, the objective is a Daily Pie Chart of Energy Consumtion.
I'm also getting the message: "Error using Testing (Pie Chart) (line 20). Channel ID must be a positive integer." But my code doesen't even have 20 lines and my Channel ID is a positive integer.
The simple code below:
readChannelID = 123456; % exemple of how the channelId written in the original code
fieldID1 = 1;
fieldID2 = 2;
readAPIKey = '6RW0V0UCJ7TPV24R';
etv = thingSpeakRead(readChannelID, 'Field', fieldID1, 'NumPoints', 1, 'Readkey', readAPIKey); % energy from TV
eil = thingSpeakRead(readChannelID, 'Field', fieldID2, 'NumPoints', 1, 'Readkey', readAPIKey); % energy from illumination
X = [etv eil];
pie(X);
Thanks for the help and sorry if i made an english mistake. I'm from Brasil.

Antworten (1)

Does your data have NaN's in the field? You can find this out by exporting the channel data from the 'Data Import/Export' tab of the channel. If you do have NaN in the data, you will first want to remove the NaN's in the data before passing it to the PIE function.
Another note - you can optimize your code to make a single call to thingSpeakRead and read multiple fields from the channel. For example
ChannelData = thingSpeakRead(<CHANNELID>, 'Fields', [1 2], 'Numpoints',8000, 'Readkey', <READKEY>);
will give you 8000 points of field 1 and field 2 in a single call. You can access the first column using
ChannelData(:,1)

3 Kommentare

I made some tests and I figured out some things:
  • The chart is getting the watt-hour values that are < than 1 and considering it as if they were percentagens. So, when it receives 0.53 and 0.17 watt-hour ... it becomes 53% and 17%. I tested and if the values used are > 1 the function Pie() calculates automatically the sum and show the correct percentages. This is why there is always missing a part of the chart (100% - 53% - 17%). There's any specification that I can do in Pie() to always do the calculation even if the values are <1?
  • I realized that I was using the graph to compare just the last value of the energy consumption received (always the last incremental part) and not the sum. In the field charts I'm already using the daily sum option. There's a way that I can read the Sum from the field and not only the last value received (like I'm doing now)?
For the problem with values < 1 I solved just by using an "if" :
  • if the sum of the numbers is <1 -> multiply each one by 100
But I still can't display in the pie chart the value of the daily sum (altough it's displayed as a "daily sum" in the field chart)
You can use the 'NumValues' optional argument to thingSpeakRead function with another optional parameter being 'outputFormat'. See documentation here.
Then from the resulting table you can sum up the values for the particular day and use that in your pie chart.

Melden Sie sich an, um zu kommentieren.

Communitys

Weitere Antworten in  ThingSpeak Community

Kategorien

Mehr zu ThingSpeak finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 4 Okt. 2019

Kommentiert:

am 8 Okt. 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by