Graph line with different colors above and below a certain value | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
Graph line with different colors above and below a certain value
No permission to create posts
January 25, 2018
4:08 am
Avatar
uphillbattle

Silver
Members
Forum Posts: 5
Member Since:
June 22, 2016
sp_UserOfflineSmall Offline

Hi,

I'm posting weather data to a few channels on ThingSpeak, for example this outdoor temperature:

https://thingspeak.com/channels/130083/charts/1?bgcolor=%23ffffff&color=%23d62020&dynamic=true&results=60&type=line

 

I know how to change the color for the entire line in the graph, but since this is an outdoor temperature in Norway - where the temperature changes between above and below freezing on a regular basis - it would be really nice to have the graph line have different colors above and below freezing. Specifically, I would like it to be blue below 0 (freezing point on the Centigrade scale) and red above 0.

Any ideas how to do that?

January 26, 2018
12:06 am
Avatar
rw950431

Top
Members
Forum Posts: 267
Member Since:
January 30, 2014
sp_UserOfflineSmall Offline

I dont know if any way to modify the thingspeak basic grapsh.  If you use a Matlab visualization you can sort your values into 2 series (above and below zero in your case) and plot them on the same graph with different colors.  

 

Hopefully someone with matlab skills can give us code for that..

January 26, 2018
3:49 pm
Avatar
Adarsh_Murthy

MathWorks
Members
Forum Posts: 62
Member Since:
August 25, 2015
sp_UserOfflineSmall Offline

Here is an example MATLAB code snippet to help you get started:

% Read data from your channel

[data, time] = thingSpeakRead(130083, 'NumPoints', 8000, 'Fields', 1);

% Create variables for holding values greater than zero and less than zero
dataGtZero = NaN(1, length(data));
dataLsZero = NaN(1, length(data));

% Assign values to the variables

% dataGtZero has all values of data that are greater than zero
dataGtZero(data>0) = data(data>0);

% dataLsZero has all values of data that are less than zero
dataLsZero(data<0) = data(data<0);

% Plot both chunks of data and specify color to be blue ('b') for data less than zero and red for the other.

plot(time, dataLsZero, 'b');
hold on;
plot(time, dataGtZero, 'r')

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
25 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 261

Vinod: 196

piajola: 85

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

Newest Members:

JamesVex, meghanfr69, raqueldk69, soniafw2, vitalijDrine, JosephAmapy

Administrators: Hans: 387, lee: 457